Cod sursa(job #394109)
| Utilizator | Data | 10 februarie 2010 16:12:59 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.38 kb |
#include<fstream>
using namespace std;
long const a = 1999999973;
long long power(long long x,long long y)
{
if(y == 0)return 1;
if(y % 2 == 0) return power((x*x)%a,y/2)%a;
else return (x*power((x*x)%a,y/2)%a)%a;
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long x,p;
fin>>x>>p;
fout<<power(x,p);
fin.close();
fout.close();
return 0;
}