Cod sursa(job #954186)
| Utilizator | Data | 28 mai 2013 16:33:42 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include<fstream>
using namespace std;
const int diviz=1999999973;
int n,p;
void citire()
{
ifstream fin("lgput.in");
fin>>n>>p;
fin.close();
}
int power(int x,int put)
{
if (put==0)
return 1;
else if (put==1)
return x;
else if (put%2)
return (x*power(x*x,(put-1)>>1))%diviz;
else
return power(x*x,(put>>1))%diviz;
}
void afisare()
{
ofstream fout("lgput.out");
fout<<power(n,p)<<'\n';
fout.close();
}
int main()
{
citire();
afisare();
return 0;
}