Cod sursa(job #3306312)
| Utilizator | Data | 9 august 2025 16:01:50 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
long long fastExpo(long long a, long long b, int mod) {
long long res = 1;
while (b > 0) {
if (b % 2 == 1) {
res = (res * a) % mod;
}
a = (a * a) % mod;
b = b / 2;
}
return res;
}
int main() {
int a, n;
fin >> a >> n;
fout << fastExpo(a, n - 2, n);
return 0;
}
