Cod sursa(job #1059403)
Utilizator | Data | 16 decembrie 2013 17:34:23 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include<fstream>
using namespace std;
const int mod = 1999999973;
int main() {
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n, p, aux = 1;
fin >> n >> p;
while(p > 1) {
if(p % 2 == 1) {
aux *= n;
aux %= mod;
n *= n;
n %= mod;
p = (p-1)/2;
} else {
n *= n;
n %= mod;
p /= 2;
}
}
n *= aux;
n %= mod;
fout << n;
return 0;
}