Cod sursa(job #814712)
| Utilizator | Data | 15 noiembrie 2012 22:10:03 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
# include <cstdio>
using namespace std;
unsigned long long int a,b,n,c,i,d,bin[101];
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld %lld",&a,&b,&n);
bin[0]=0;c=0;d=1;
while(b)
{
bin[++bin[0]]=b%2;
b/=2;
}
for(i=bin[0];i>=1;i--)
{
d=(d*d)%n;
if(bin[i])d=(d*a)%n;
}
printf("%lld\n",d);
return 0;
}
