Cod sursa(job #2786141)
| Utilizator | Data | 20 octombrie 2021 13:23:45 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
typedef long long ll;
ll rise_to_power(ll n, ll p) {
if (p == 1) {
return n % 1999999973;
}
if (p % 2 == 0) {
return rise_to_power(n, p / 2) % 1999999973 * rise_to_power(n, p / 2) % 1999999973;
}
if (p % 2 != 0) {
return rise_to_power(n, p / 2) % 1999999973 * rise_to_power(n, p / 2) % 1999999973 * n % 1999999973;
}
}
int main() {
ll n, p;
fin >> n >> p;
fout << rise_to_power(n, p);
}
