Cod sursa(job #1248433)
Utilizator | Data | 25 octombrie 2014 10:08:22 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include<iostream>
#include<fstream>
using namespace std;
const long long max = 1999999973;
int main(){
ifstream f("lgput.in", ios::in);
ofstream g("lgput.out", ios::out);
long long N, P, prod = 1;
f >> N >> P;
while (P >= 1){
if(P%2==1){
prod = (prod*N)%max;
}
N = (N*N)%max;
P /= 2;
}
g << prod << '\n';
f.close();
g.close();
return 0;
}