Cod sursa(job #1852811)
Utilizator | Data | 21 ianuarie 2017 10:51:16 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 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=9223372036854775808;
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;
}