Cod sursa(job #1852816)
Utilizator | Data | 21 ianuarie 2017 10:52:28 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long x, p, rez=1, R=1999999973;
fin >> x >> p;
while(p){
if(p%2==1){
rez=rez*x;
rez%=R;
}
x=x*x;
x%=R;
p/=2;
}
fout << rez;
return 0;
}