Cod sursa(job #1992761)
Utilizator | Data | 21 iunie 2017 13:22:46 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int M = 1999999973;
long long a, aa, p, x, er;
int main()
{
fin >> aa >> p;
a = aa;
x = er = 1;
while(p > 0)
{
while(2 * x <= p)
{
a *= a;
a %= M;
x *= 2;
}
p -= x;
x = 1;
er *= a;
er %= M;
a = aa;
}
fout << er;
return 0;
}