Cod sursa(job #1040289)
| Utilizator | Data | 24 noiembrie 2013 12:42:44 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int m = 1999999973;
int n, p, k;
int lgput (int a, int b){
if (b == 0)
return 1;
if (b == 1)
return a;
int x = lgput (a , b/2);
if (b % 2 == 0)
return x * x;
else
return x * x * a;
}
int main()
{
in>>n>>p;
k = lgput (n, p) % m;
out<<k;
}
