Cod sursa(job #3329539)

Utilizator DariusJohnDarius Dumitrescu DariusJohn Data 13 decembrie 2025 21:11:02
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");

void gcd(long long &x, long long &y, long long a, long long b) {
  if (b == 0) {
    x = 1;
    y = 0;
  } else {
    gcd(x, y, b, a % b);
    long long aux = x;
    x = y;
    y = aux - y * (a / b);
  }
}

int main() {
  long long a, n, inv = 0, ins = 0;
  fin >> a >> n;
  gcd(inv, ins, a, n);
  inv = (inv % n + n) % n;
  fout << inv;
}