Cod sursa(job #2987613)
Utilizator | Data | 2 martie 2023 16:46:53 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
long long n, p, rez = 1, mod = 1999999973;
int main()
{
fin >> n >> p;
while (p > 0)
{
if (p % 2==0)
{
n *= n;
n %= mod;
p /= 2;
}
else
{
rez *= n;
rez %= mod;
p--;
}
}
fout << rez;
return 0;
}