Cod sursa(job #2264066)
Utilizator | Data | 19 octombrie 2018 19:38:33 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long putere(long a,long x)
{
int p;
if(x==0)
return 1;
if(x==1)
return a%1999999973;
if(x%2)
{
p=putere(a,(x-1)/2);
return p*p*a%1999999973;
}
else
{
p=putere(a,x/2);
return p*p%1999999973;
}
}
int main()
{
long n,p;
f>>n>>p;
g<<putere(n,p);
}