Cod sursa(job #558179)
| Utilizator | Data | 17 martie 2011 09:38:17 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream intrare("lgput.in");
ofstream iesire("lgput.out");
int n, px, modulo=1999999973;
int main()
{
int rez1, rez2, x, rest, sol;
intrare>>x>>n;
px=x;
rez1=1;
rez2=1;
while (n)
{
rest=n%2;
if (rest==1)
rez1*=px;
px*=px;
n/=2;
if (n==0){sol=rez1%modulo;break;}
else
{
rest=n%2;
if (rest==1)
rez2*=px;
px*=px;
n/=2;
}
sol=((rez1%modulo)*(rez2)%modulo)%modulo;
}
iesire<<sol;
return 0;
}