Cod sursa(job #2397842)
| Utilizator | Data | 4 aprilie 2019 20:04:40 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int f(long long n,int p)
{
if(n==0)
{
return 1;
}
if(p==1)
{
return n;
}
if(p==0)
{
return 1;
}
if(p%2==0)
{
return (f(n,p/2)%1999999973*f(n,p/2)%1999999973)%1999999973;
}
else
{
return (f(n%1999999973,p/2)%1999999973*f(n%1999999973,p/2)%1999999973 * n);
}
}
int main()
{
long long n,p;
fin>>n>>p;
fout<<f(n,p);
}
