Cod sursa(job #1797131)
| Utilizator | Data | 3 noiembrie 2016 23:49:10 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <stdio.h>
#define MOD 1999999973
using namespace std;
FILE *fin = fopen("lgput.in", "r");
FILE *fout = fopen("lgput.out", "w");
long long pow(long long x, long long n) {
long long p = 1;
while (n > 0) {
if ((n & 1) == 1) {
p = (p * x) % MOD;
n--;
}
x = (x * x) % MOD;
n /= 2;
}
return p;
}
int main() {
long long x, n;
fscanf(fin, "%lld %lld", &x, &n);
fprintf(fout, "%lld", pow(x, n));
fclose(fin);
fclose(fout);
return 0;
}
