Cod sursa(job #1152059)
Utilizator | Data | 24 martie 2014 15:30:36 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
using namespace std;
ifstream fin("1.in");
ofstream fout("1.out");
int n,p;
long long exp(int x,int y)
{
if(!y)return 1;
else
if(y%2) return(x%1999999973)*(exp(x, y-1)%1999999973)%1999999973;
else
{
long long p2;
p2=exp(x,y/2)%1999999973;
return (p2%1999999973)*(p2%1999999973)%1999999973;
}
}
int main()
{
fin>>n>>p;
fout<<exp(n,p)<<'\n';
return 0;
}