Cod sursa(job #1481646)
| Utilizator | Data | 5 septembrie 2015 00:00:17 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <cstdio>
#include <cstdlib>
using namespace std;
const int mod = 1999999973;
int n, k;
int pow(int n, int k) {
if (k == 0)
return 1;
if (k == 1)
return n;
if (k % 2 == 1)
return 1LL * n * pow(n * n, k / 2) % mod;
else
return 1LL * pow(n * n, k / 2) % mod;
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d %d", &n, &k);
printf("%d", pow(n, k));
return 0;
}
