Cod sursa(job #2044853)
Utilizator | Data | 21 octombrie 2017 15:16:30 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int MOD = 1999999973;
long long n, p, ans = 1;
int main()
{
fin >> n >> p;
for (int i = 0; (1 << i) <= p; ++i) {
if ((p & (1 << i)) > 0)
ans = ((ans % MOD) * (n % MOD)) % MOD;
n = ((n % MOD) * (n % MOD)) % MOD;
}
fout << ans;
fin.close();
fout.close();
return 0;
}