Cod sursa(job #3211917)

Utilizator ShadowZoidPorojan Victor-Andrei ShadowZoid Data 10 martie 2024 17:38:42
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
int n,i,a,b,c,x,x1,y,y1,d;
void euclid(int a,int b)
{
    if(b==0)
    {
        d=a;
        x=x1=1;
        y=y1=0;
    }
    else
    {
        euclid(b,a%b);
        x=y1;
        y=x1-(a/b)*y1;
        x1=x;
        y1=y;
    }
}
int main()
{
    cin>>a>>n;
    euclid(a,n);
    if(x<=0)
        x+=n;
    cout<<x;
    return 0;
}