Cod sursa(job #2183153)
Utilizator | Data | 22 martie 2018 21:04:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n,p;
int putere(int x, int y) {
if(y==1) return x;
else if(y%2==1) return x*putere(x*x,(y-1)/2);
else if(y%2==0) return putere(x*x,y/2);
}
int main()
{
fin>>n>>p;
fout<<putere(n,p)%1999999973;
return 0;
}