Cod sursa(job #940027)
Utilizator | Data | 15 aprilie 2013 14:19:16 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include<fstream>
using namespace std;
const int mo=1999999973;
long long x;
int p;
long long pow(int p)
{
long long y;
if (p==1)
return x;
if (p%2==1)
{
y=pow(p-1);
return x*y%mo;
}
else
{
y=pow(p/2);
return y*y%mo;
}
}
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f >> x >> p;
g << pow(p);
return 0;
}