Cod sursa(job #3164931)

Utilizator tonealexandruTone Alexandru tonealexandru Data 4 noiembrie 2023 19:57:23
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <bits/stdc++.h>
#include <fstream>
#define int long long

using namespace std;

void invmod(int a, int b, int &d, int &x, int &y)
{
    if(b==0)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        int x0, y0;
        invmod(b, a%b, d, x0, y0);
        x=y0;
        y=x0-(a/b)*y0;
    }
}

int32_t main()
{
    ifstream cin("inversmodular.in")
    ofstream cout("inversmodular.out")
    int a,n,b,x,c;
    cin>>a>>n;
    invmod(a,n,b,x,c);
    if(x<0)
        x+=n;
    cout<<x;

    return 0;
}