Cod sursa(job #1963266)
Utilizator | Data | 12 aprilie 2017 13:32:29 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long a, b, ans, mod = 1999999973;
int main () {
ifstream fin("lgput.in");
ofstream fout("lgput.out");
fin >> a >> b;
ans = 1;
while (b != 0)
{
if (b % 2 == 0)
{
b /= 2;
a = (a*a) % mod;
}
else
{
ans = (ans*a) % mod;
b--;
}
}
fout << ans;
return 0;
}