Cod sursa(job #2983837)
| Utilizator | Data | 23 februarie 2023 09:56:22 | |
|---|---|---|---|
| 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;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n, p;
long long riseToPower(long long n, long long p) {
long long rest = 1;
n %= 1999999973;
while (p) {
if (p % 2) {
rest *= n % 1999999973;
}
n *= n % 1999999973;
p /= 2;
}
return rest;
}
int main() {
fin >> n >> p;
fout << riseToPower(n, p);
return 0;
}