Cod sursa(job #1121125)
Utilizator | Data | 25 februarie 2014 11:40:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <cstdio>
#define mod 1999999973
using namespace std;
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
unsigned int n, p;
long long x, power=1;
scanf("%d%d", &n, &p);
x=n;
for(unsigned int i=0;(1<<i)<=p;i++)
{
if(((1<<i)&p)>0)
power=(power*x)%mod;
x=(x*x)%mod;
}
printf("%lld", power);
return 0;
}