Cod sursa(job #1872820)
Utilizator | Data | 8 februarie 2017 16:55:55 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#define LL long long
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
LL N, P, sol = 1;
fin>>N>>P;
while(P) {
if(P%2 == 1) {
sol = ((sol%MOD) * (N%MOD))%MOD;
}
N = ((N%MOD)*(N%MOD))%MOD;
P /= 2;
}
fout<<sol<<'\n';
fin.close();
fout.close();
return 0;
}