Cod sursa(job #558155)
Utilizator | Data | 17 martie 2011 09:33:01 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.31 kb |
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, p;
int main()
{
int rez=1, putere, rest;
fin>>n>>p;
putere=p;
while(n)
{
rest=n%2;
if(rest==1)
rez*=putere;
n/=2; putere*=putere;
}
fout<<rez%1999999973;
fout.close();
return 0;
}