Cod sursa(job #2943709)
| Utilizator | Data | 21 noiembrie 2022 15:47:52 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int M = 1999999973;
int putere(int a, int n)
{
int p = 1;
while (n != 0)
{
int cif = n % 2;
if (cif != 0)
{
p = (long long)p * a % M;
}
a = (long long)a * a % M;
n /= 2;
}
return p;
}
int main()
{
int N, P;
in >> N >> P;
out << putere(N, P) << endl;
return 0;
}
