Cod sursa(job #2878334)
Utilizator | Data | 26 martie 2022 15:34:32 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("lgput.in");
ofstream g ("lgput.out");
const int MOD = 1999999973;
int LogExp(int n, int p)
{
int ans = 1;
while (p != 0)
{
if (p % 2 == 1)
{
ans = (ans * n) % MOD;
}
n = (n * n) % MOD;
p = p / 2;
}
return ans;
}
int main()
{
int n, p;
f >> n >> p;
g << LogExp(n, p);
}