Cod sursa(job #932122)
Utilizator | Data | 28 martie 2013 18:34:28 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<iostream>
#include<fstream>
#define inf 1999999973
using namespace std;
int n, p, a=1, put;
ifstream f("lgput.in");
ofstream g("lgput.out");
int lgput(){
while(p!=1){
if(p%2==0)
n=n*n%inf, p/=2;
else
a=a*n%inf, --p;
//cout<<a*n<<' ';
}
return (a*n)%inf;
}
int main()
{
f>>n>>p;
g<<lgput()<<' ';
return 0;
}