Cod sursa(job #2504835)
Utilizator | Data | 5 decembrie 2019 17:29:17 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
int lgput(int n, int exp)
{
if(exp==1)
return n;
if(exp==0)
return 1;
if(exp%2==0)
return lgput(n*n, exp/2);
return ((n%1999999973)*lgput(n*n, exp/2))%1999999973;
}
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
int n, p; fin>>n>>p;
fout<<lgput(n, p);
fin.close();
fout.close();
return 0;
}