Cod sursa(job #1963353)
| Utilizator | Data | 12 aprilie 2017 14:25:04 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <cstdio>
#include <cstring>
#define MOD 1999999973
#define lint long long
using namespace std;
lint n, p;
lint putLog(lint x, lint y)
{
if (y == 1)
return x;
else if (y % 2 == 0)
return putLog((x * x) % MOD, (y / 2) % MOD) % MOD;
else
return x * putLog((x * x) % MOD, (y / 2) % MOD) % MOD;
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%lld %lld", &n, &p);
printf("%lld", putLog(n, p));
return 0;
}
