Cod sursa(job #751144)
Utilizator | Data | 24 mai 2012 17:25:54 | |
---|---|---|---|
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;
int main(){
int n,p,w,y,cp;
long long x,k;
ifstream in("lgput.in");
ofstream out("lgput.out");
in>>n>>p;
x=n;
k=1;
w=1999999973;
y=1;
cp=p;
while(p>0){
while(p%2==0){
x=(long long)(x*x)%w;
p=p/2;
y=y*2;
}
p=p-1;
if(p==0){
p=cp-y;
cp=p;
y=1;
k=(long long)(k*x)%w;
x=n;
}
}
out<<k;
return 0;
}