Cod sursa(job #664609)
| Utilizator | Data | 20 ianuarie 2012 15:04:46 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include<cstdio>
int cif[100];
int main(){
unsigned long long int a,b,i=0,p=1,j;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld", &a, &b);
while(b){
if(b%2==1) cif[++i]=1;
else cif[++i]=0;
b=b/2;
}
for(j=i;j>=1;--j){
if(cif[j]==1){
p=((p%1999999973)*(p%1999999973)*(a%1999999973))%1999999973;
}
else p=((p%1999999973)*(p%1999999973))%1999999973;
}
printf("%lld", p);
}
