Cod sursa(job #2349292)
Utilizator | Data | 20 februarie 2019 12:46:48 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#include <cstring>
#include <algorithm>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int MOD = 1999999973;
int n, p;
int main() {
fin >> n >> p;
int s = 1;
int a = n;
for (int i = 1; i <= p; i <<= 1) {
if (i & p) {
s = s * a % MOD;
}
a *= a;
}
fout << s;
fout.close();
return 0;
}