Cod sursa(job #2130099)

Utilizator andrei_diaconu11Andrei C. Diaconu andrei_diaconu11 Data 13 februarie 2018 13:54:00
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fi("inversmodular.in");
ofstream fo("inversmodular.out");

void euclidex(int a, int b, long long &x, long long &y){
  if(b == 0){
    x = 1;
    y = 0;
    return;
  }
  euclidex(b, a % b, x, y);
  long long aux = y;
  y = x - 1LL * (a / b) * y;
  x = aux;
}

int main()
{
  int a, b;
  long long x, y;
  fi >> a >> b;
  euclidex(a, b, x, y);
  x = (x + b) % b;
  fo << x;
  fi.close();
  fo.close();
  return 0;
}