Cod sursa(job #2065426)
Utilizator | Data | 13 noiembrie 2017 19:35:49 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
#define tip long long
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
tip N,P,M=1999999973,putere(tip,tip,tip);
int main()
{
f>>N>>P;
g<<putere(N,P,M);
return 0;
}
tip putere(tip b,tip e,tip m)
{
tip r=1LL;
while(e)
{
if(e%2)r=r*b%m;
b=b*b%m;
e/=2;
}
return r;
}