Cod sursa(job #1390140)
Utilizator | Data | 16 martie 2015 21:26:06 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
#define rest 1999999973;
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p,sol;
int main()
{
f>>n>>p;
sol=1;
while(p>0){
if(p%2==0)
n=(n*n)%rest
else
{
sol=(sol*n)%rest;
n=(n*n)%rest;
}
p=(int)(p/2);
}
g<<sol<<"\n";
f.close();
g.close();
return 0;
}