Cod sursa(job #1064655)
Utilizator | Data | 22 decembrie 2013 10:27:57 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <cstdio>
#define LL long long
using namespace std;
const LL MOD = 1999999973;
int main() {
LL n, p, i, nr;
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%lld%lld", &n, &p);
nr = 1;
for (i = 1; i <= p; i <<= 1) {
if (p & i) nr = (nr * n) % MOD;
n = (n * n) % MOD;
}
printf("%d", nr);
return 0;
}