Cod sursa(job #1562875)
Utilizator | Data | 5 ianuarie 2016 15:48:50 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <cstdio>
using namespace std;
const int mod = 1999999973;
int n,p,r = 1;
int main() {
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d %d", &n, &p);
while(p) {
if(p % 2) {
r *= n;
r %= mod;
}
n *= n;
n %= mod;
p /= 2;
}
printf("%d\n", r);
return 0;
}