Cod sursa(job #2141376)
Utilizator | Data | 24 februarie 2018 12:13:49 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 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");
lint DEIPower(lint x, lint P) {
if (P == 1) return x;
if (P % 2 == 0) {
return DEIPower((x * x) % MOD, P / 2) % MOD;
}
return x * DEIPower((x * x) % MOD, P / 2) % MOD;
}
int main()
{
fin >> N >> P;
N %= MOD;
fout << DEIPower(N, P) % MOD;
return 0;
}