Cod sursa(job #895606)
Utilizator | Data | 27 februarie 2013 11:56:57 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#include <string.h>
const int m = 1999999973;
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long r,n,p;
int main()
{
r=1;
f >> n >> p;
while(p!=0){
if(p%2==0){
n=(n*n)%m;
p=p/2;
}
else{
r=(r*n)%m;
p-=1;
n=(n*n)%m;
p=p/2;
}
}
g<<r;
return 0;
}