Cod sursa(job #3346390)
| Utilizator | Data | 13 martie 2026 15:14:55 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
int a, n;
int putere (int x, int y) {
if (y == 0)
return 1;
if (y % 2 == 0) {
int z = putere(x, y / 2);
return 1LL * z * z % n;
}
else
return 1LL * x * putere (x, y - 1) % n;
}
int main() {
fin >> a >> n;
fout << putere (a, n - 2);
return 0;
}
