Cod sursa(job #615528)
Utilizator | Data | 9 octombrie 2011 22:18:20 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int M = 1999999973;
int lgpow(int x,int y)
{
int ans = 1;
for(;y>1;y>>=1)
{
if(y % 2)
ans = (1LL * ans * x) % M , y--;
x = (1LL * x * x) % M;
}
return ans;
}
int main()
{
int n , p;
fin>>n>>p;
fout<<lgpow(n,p)<<'\n';
return 0;
}