Cod sursa(job #2675073)
Utilizator | Data | 21 noiembrie 2020 09:51:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
#include <cmath>
using namespace std;
int power(int n,int p)
{
int r=1;
while(p!=0)
{
if(p%2)
return power(1LL * n * n%1999999973, p/2);
else if(p%2!=0)
return 1LL * n * power(1LL*n*n%1999999973,(p-1)/2)%1999999973;
else
return r;
}
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, p;
fin>>n>>p;
fout<<power(n,p);
return 0;
}