Cod sursa(job #558212)
Utilizator | Data | 17 martie 2011 09:54:45 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, p;
int main()
{
int pn, sol, rest;
fin >> p >> n;
pn=p;
sol=1;
while(n)
{
rest=n%2;
if(rest)
{
sol=(sol%1999999973*pn%1999999973)%1999999973;
}
n/=2;
pn=(pn*pn)%1999999973;
}
fout << sol << '\n';
fout.close();
return 0;
}