Cod sursa(job #1819940)

Utilizator GeoeyMexicanuBadita George GeoeyMexicanu Data 30 noiembrie 2016 23:40:44
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void eucl(int a,int n,int &x,int &y)
{
    if(n==0)
    {
        x=1;
        y=0;
    }
    else
    {
        int x0,y0;
        eucl(n,a%n,x0,y0);
        x=y0;
        y=x0-(a/n)*y0;
    }
}
int main()
{
    int A,N,x,y;
    f>>A>>N;
    eucl(A,N,x,y);
    if(x<0)
        x+=N;
    g<<x<<"\n";
    return 0;
}