Cod sursa(job #3194651)
Utilizator | Data | 18 ianuarie 2024 20:31:01 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("lgput.in");
ofstream out("lgput.out");
int mod = 1999999973;
long long n, p;
int i = 1;
in >> n >> p;
while (p > 0)
{
if (p % 2 == 0)
{
n = (n * n) % mod;
p /= 2;
}
else
{
i = (i * n) % mod;
p--;
}
}
out << n;
return 0;
}