Cod sursa(job #1387648)
Utilizator | Data | 14 martie 2015 15:38:15 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#define MODULO 1999999973
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
long long n,p;
int lgputere(int baza,int exp)
{
p=1;
while(exp)
{
if(exp%2==1) p=p*baza%MODULO;
exp=exp/2;
baza=baza*baza%MODULO;
}
return p;
}
int main()
{
in>>n>>p;
out<<lgputere(n,p);
in.close();
out.close();
return 0;
}