Cod sursa(job #2906517)

Utilizator bucketlover413Sodinca Iulia Cristiana bucketlover413 Data 26 mai 2022 15:38:34
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int main()
{

long long int y0 = 0, y1 = 1, M, a, aux, r, c, y ;
fin>>a>>M;
aux = 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;
}
fout << y0;
    return 0;
}