Cod sursa(job #494371)
| Utilizator | Data | 21 octombrie 2010 15:27:55 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream.h>
ifstream f("lgput.in");
ofstream g("lgput.out");
unsigned long putere(unsigned long x, unsigned long n)
{
if(n==1)
return x % 1999999973;
if(n%2==0)
return (putere(x,n/2)%1999999973)*(putere(x,n/2)%1999999973);
return (putere(x,(n-1)/2)%1999999973)*(putere(x,(n+1)/2)%1999999973);
}
int main()
{
unsigned long x,n;
f>>x>>n;
g<<putere(x,n);
f.close();
g.close();
return 0;
}
