Cod sursa(job #1729429)
Utilizator | Data | 14 iulie 2016 18:23:56 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p;
int putere(int x,int n)
{
if(n==0)
{
return 1;
}
long aux=putere(x,n/2);
if(n%2==0)
{
return aux*aux;
}
if(n%2==1)
{
return x*aux*aux;
}
}
int main()
{
f>>n>>p;
g<<putere(n,p)%1999999973;
f.close();
g.close();
return 0;
}