Cod sursa(job #1615706)
Utilizator | Data | 26 februarie 2016 19:37:25 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include<cstdio>
using namespace std;
long long rez,a,b;
int main(){
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld%lld",&a,&b);
a=a%1999999973;
rez=1;
while(b!=0){
if(b%2==0){
a=(a*a)%1999999973;
b/=2;
}
else{
rez=(rez*a)%1999999973;
b--;
}
}
printf("%lld",rez);
return 0;
}