Cod sursa(job #3194656)
Utilizator | Data | 18 ianuarie 2024 20:37:00 | |
---|---|---|---|
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>
using namespace std;
int main()
{
ifstream in("lgput.in");
ofstream out("lgput.out");
int mod = 1999999973;
long long n, p;
int eredmeny = 1;
in >> n >> p;
while (p > 0)
{
if (p % 2 == 0)
{
n = (n * n) % mod;
p /= 2;
}
else
{
eredmeny = (eredmeny * n) % mod;
p--;
}
}
out << eredmeny;
return 0;
}