Cod sursa(job #2141356)
| Utilizator | Data | 24 februarie 2018 12:01:02 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
#define MOD 1999999973
using namespace std;
typedef unsigned long long int lint;
lint N, P;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
unsigned long long int DEIPower(lint x, lint P) {
if (P == 1) return x % MOD;
if (P % 2 == 0) {
return DEIPower((x * x) % MOD, P / 2);
}
return x * DEIPower((x * x) % MOD, P / 2);
}
int main()
{
fin >> N >> P;
N %= MOD;
fout << DEIPower(N, P) % MOD;
return 0;
}
