Cod sursa(job #3293361)
| Utilizator | Data | 11 aprilie 2025 15:44:18 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
using namespace std;
long long lgput(long long base, long long exp, long long mod) {
long long res = 1;
base %= mod;
while (exp) {
if (exp % 2) res = (res * base) % mod;
base = (base * base) % mod;
exp /= 2;
}
return res;
}
int main() {
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long N, P;
fin >> N >> P;
fout << lgput(N, P, 1999999973);
return 0;
}
