Cod sursa(job #1182414)
Utilizator | Data | 6 mai 2014 12:50:38 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
int main(){
ifstream ifs("lgput.in");
ofstream ofs("lgput.out");
long long int x,n,a=1,m=1999999973;ifs>>x>>n; // x^n
while(n!=0){
if(n%2){
a=(a*x)%m;
x=(x*x)%m;
n>>=1;
}
else{
x=(x*x)%m;
n>>=1;
}
}
ofs<<a;
}