Cod sursa(job #3276211)
Utilizator | Data | 12 februarie 2025 21:38:27 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int n, a;
void gcd(int a, int b, long long& x, long long& y)
{
if (b == 0)
{
x = 1;
y = 0;
}
else
{
gcd(b, a % b, x, y);
long long temp = x;
x = y;
y = temp - y * (a / b);
}
}
int main()
{
f >> a >> n;
long long x, y;
gcd(a, n, x, y);
if (x <= 0)
x = n + x % n;
g << x;
}