Cod sursa(job #1969998)
Utilizator | Tudor Maxim tudormaxim | Data | 18 aprilie 2017 19:41:35 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
typedef long long LL;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
const LL mod = 1999999973;
LL Fast_pow(LL n, LL p) {
LL ans = 1LL;
while (p) {
if (p & 1) ans = (ans * n) % mod;
n = (n * n) % mod;
p = p >> 1;
}
return ans;
}
int main() {
ios_base :: sync_with_stdio(false);
LL n, p;
fin >> n >> p;
fout << Fast_pow(n, p) << "\n";
return 0;
}