Cod sursa(job #2870904)
Utilizator | Data | 12 martie 2022 17:30:57 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
#include <vector>
#define MOD 1999999973
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
long long n,p;
int main()
{
long long s=1;
fin >> n >> p;
while(p)
{
if(p & 1)
{
s = s * n;
s = s % MOD;
--p;
}
else
{
n = n*n;
n=n%MOD;
p = (p >> 1);
}
}
fout <<s;
return 0;
}