Cod sursa(job #2900378)

Utilizator zsoltzsoltDirirczi Zsolt zsoltzsolt Data 10 mai 2022 19:41:32
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
	
#include <bits/stdc++.h>
using namespace std;

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

int main(void){
    int y0 = 0, y1 = 1;
    int M;
    int aux = M;
    int r,c,y;
    int a;
    in >> a;
    in >> M;
    while (a != 0)
    {
        r = M % a;
        c = M / a;
        M = a;
        a = r;
        y = y0-c*y1;
        y0 = y1;
        y1 = y;
    }

    while (y0 < 0)
    {
        y0 += aux;
    }
    out << y0;
}