Cod sursa(job #1854034)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 22 ianuarie 2017 12:34:35
Problema Invers modular Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

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

int a, n;

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

int main() {
  int x, y;
  in>>a>>n;
  gcd(x, y, a, n);
  out<<fabs(x);
  return 0;
}