Cod sursa(job #232160)
| Utilizator | Data | 14 decembrie 2008 20:51:35 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include<stdio.h>
long long a;
long long b;
char d[100];
long long q;
#define mod 1999999973
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld", &a, &b);
while (b)
{
d[++d[0]] = b % 2;
b /= 2;
}
q = 1;
for(int i = d[0]; i > 0; i--)
{
q = (q * q) % mod;
if (d[i])
{
q = (q * a) % mod;
}
}
printf("%lld \n", q);
return 0;
}
