Cod sursa(job #2573140)

Utilizator BogdanRazvanBogdan Razvan BogdanRazvan Data 5 martie 2020 16:00:52
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");

void usain_bolt()
{
    ios::sync_with_stdio(false);
    fin.tie(0);
}

long long ext_gcd(long long a, long long b, long long & x, long long & y)
{
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long x1, y1;
    long long d = ext_gcd(b, a % b, x1, y1);
    y = x1 - (a / b) * y1;
    x = y1;
    return d;
}

int main()
{
    usain_bolt();

    long long a, n;

    fin >> a >> n;

    long long x = 0, y = 0;
    ext_gcd(a, n, x, y);
    x = (x + n) % n;
    fout << x;
    return 0;
}