Cod sursa(job #2480455)
| Utilizator | Data | 25 octombrie 2019 17:13:42 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
const long long X = 1999999973;
long long lgput(long long N, long long P)
{
long long rez = 1;
while(P > 0)
{
if(P & 1)
{
rez *= N;
rez %= X;
P--;
}
N*=N;
N%=X;
P>>=1;
}
return rez;
}
int main()
{
long long N,P;
in >> N >> P;
out << lgput(N,P);
return 0;
}
