Cod sursa(job #1831103)
| Utilizator | Data | 17 decembrie 2016 15:10:29 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#define MOD 1999999973
long long expo(long long a, long long b){
if (b==1)
return a%MOD;
if (b==2)
return (a%MOD * a%MOD)%MOD;
if (b%2==0){
return expo(expo(a, b/2), 2);
}
else{
return a * expo(expo(a, (b-1)/2), 2);
}
}
//-----------------------
int main() {
FILE *file1, *file2;
long long N, P;
file1 = fopen("lgput.in", "r");
file2 = fopen("lgput.out", "w");
fscanf(file1, "%lld", &N);
fscanf(file1, "%lld", &P);
N %= MOD;
fprintf(file2, "%lld", expo(N, P));
return 0;
}
