Cod sursa(job #2666081)

Utilizator teochess2017Togan Teodor-Bogdan teochess2017 Data 31 octombrie 2020 19:55:11
Problema Invers modular Scor 100
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <stdio.h>
#include <stdlib.h>

int x, y, d;

void cmmdc(int a, int b){
  int aux;
  if(0 == b){
    x = 1;
    y = 0;
    d = a;
  }else{
    cmmdc(b, a % b);
    aux = y;
    y = x - (a / b) * y;
    x = aux;
  }
}

int main()
{
    FILE *fin, *fout;
    int n, a;
    fin = fopen("inversmodular.in", "r");
    fscanf(fin, "%d%d", &a, &n);
    fclose(fin);
    cmmdc(n, a);
    if(y < 0){
      y = y + (y / (-n)) * n + n;
    }
    fout = fopen("inversmodular.out", "w");
    fprintf(fout, "%d", y);
    fclose(fout);
    return 0;
}