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