Cod sursa(job #1979663)
Utilizator | Robert Trifan trifangrobert | Data | 11 mai 2017 01:11:17 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int MOD = 1999999973;
int n, p;
ifstream f("lgput.in");
ofstream g("lgput.out");
int Power(int n, int p)
{
long long rez = 1;
while (p)
{
if (p % 2)
{
rez = (1LL * rez * n) % MOD ;
n--;
}
p /= 2;
n = (1LL * n * n) % MOD;
}
return rez;
}
int main()
{
f >> n >> p;
g << Power(n, p) << "\n";
return 0;
}