Cod sursa(job #625478)
| Utilizator | Data | 24 octombrie 2011 19:54:11 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int x,p;
long long fastexp(long long b, int n)
{
if(n==0) return 1;
if(n<0) //return ((1/fastexp(b,-n))%1999999973);
{
long long q=fastexp(b,-n);
return (1/q)%1999999973;
}
if(n%2)
{
long long q=fastexp(b,n-1);
return (b*q%1999999973);
}
long long q=fastexp(b,n/2);
return (q*q)%1999999973;
}
int main()
{
f>>x>>p;
g<<fastexp(x,p)<<'\n';
f.close(); g.close();
return 0;
}
