Cod sursa(job #3211795)
| Utilizator | Data | 10 martie 2024 13:18:04 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int b, a;
long long ans, s;
void inversModular(long long &x, long long &y, long long a, long long b)
{
if (!b) {
x = 1, y = 0;
}
else {
inversModular(x, y, b, a % b);
long long aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
f >> a >> b;
inversModular(ans, s, a, b);
if (ans <= 0) {
ans = b + ans % b;
}
g << ans;
return 0;
}
