Cod sursa(job #2708110)
Utilizator | Data | 18 februarie 2021 12:35:52 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream f ("lgput.in");
ofstream g ("lgput.out");
int main()
{
int n, p, rez=1;
f >> n >> p;
while(p)
{
if(p%2==1)
{
p--;
rez=(rez*n)%MOD;
}
else
{
p/=2;
n=(n*n)%MOD;
}
}
g << rez;
return 0;
}