Cod sursa(job #2578993)

Utilizator driver71528@gmail.comTerec Andrei-Sorin [email protected] Data 11 martie 2020 20:22:58
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n;
void Euclid(int a,int b,int& x,int& y)
{
    if(b==0)
    {
        x=1;
        y=0;
    }
    else
    {
        int x0,y0;
        Euclid(b,a%b,x0,y0);
        x=y0 % n;
        y=(x0-a/b*y0) % n;
    }
}
int main()
{
    int x,y;
    f>>a>>n;
    f.close();
    Euclid(a,n,x,y);
    g<<x;
    return 0;
}