Cod sursa(job #1331231)

Utilizator handsonthewheelSandel Georgel handsonthewheel Data 31 ianuarie 2015 14:02:31
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb

#include <cstdio>
#define MOD 1999999973
long long fast (long long a, long long n){
    long long sol = 1;
    while (n>0){
            if (n & 1){
                    sol=(sol*a)%MOD;
                    n--;}
                    a=(a*a)%MOD;
              n>>=1;}
                    return sol%MOD;
}
int main(){
    freopen ("lgput.in", "r", stdin);
freopen ("lgput.out", "w", stdout);
long long a,n;
scanf ("%lld %lld", &a, &n);
printf ("%lld", fast(a,n));
return 0;
}