Cod sursa(job #1935389)
Utilizator | Data | 22 martie 2017 12:00:33 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int exp(int n, int p){
if(p<0)
return exp( 1/n, -p);
else
if(p==0)
return 1;
else
if(p==1)
return n;
else
if(p%2==0)
return exp(n*n%1999999973, p/2);
else
if(p%2!=0)
return exp(n*n%1999999973,p/2-1);
}
int n,p;
int main()
{
f>>n>>p;
g<< exp(n,p)%1999999973;
return 0;
}