Cod sursa(job #712412)
| Utilizator | Data | 13 martie 2012 13:58:34 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream.h>
#define mod 1999999973
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
int baza, exponent, x, t=0, i, cifre[1000];
long long p=1;
f>>baza>>exponent;
x=exponent;
while(x)
{
cifre[t]=x%2;
t++;
x=x/2;
}
for(i=t-1; i>=0; i--)
{
if(cifre[i]%2==1)
{
p=((p*p)%mod*baza)%mod;
}
else
p=(p*p)%mod;
if(p>mod)
{
p=p%mod;
}
}
g<<p;
}