Cod sursa(job #1956089)
Utilizator | Data | 6 aprilie 2017 14:47:26 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <fstream>
using namespace std;
int n,p,x,mod=1999999973;
int main()
{freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d%d", &n, &p);
x=1;
while(p)
{
if(p==1)
{
printf("%d", (x*n)%mod);
return 0;
}
if(p%2)
{
x=(x*n)%mod;
}
p=p/2;
n=(n*n)%mod;
}
printf("%d", n);
return 0;
}