Cod sursa(job #2702409)

Utilizator beingsebiPopa Sebastian beingsebi Data 3 februarie 2021 22:36:03
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void solve(int a, int b, int &x, int &y)
{
    if (!b)
        x = 1, y = 0;
    else
    {
        solve(b, a % b, x, y);
        int aux = x;
        x = y;
        y = aux - y * (a / b);
    }
}
int32_t main()
{
    int a, b, x = 0, y;
    f >> a >> b;
    solve(a, b, x, y);
    if (x < 1)
        x += b;
    g << x;
    return 0;
}