Cod sursa(job #1956102)
Utilizator | Data | 6 aprilie 2017 14:56:22 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 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%2==0)
{
p/=2;
n=(n*n)%mod;
}
else
{
x=(x*n)%mod;
p--;
}
}
printf("%d", x);
return 0;
}