Cod sursa(job #3266134)

Utilizator tudorhTudor Horobeanu tudorh Data 5 ianuarie 2025 20:38:32
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
using ll=long long;
ll cb;
void euclid(ll a,ll b,ll *x,ll *y,ll *d)
{
    if(b==0)
    {
        *x=1;
        *y=0;
        *d=a;
    }
    else
    {
        ll x0,y0;
        euclid(b,a%b,&x0,&y0,d);
        *x=y0;
        *y=x0-a/b*y0;
    }
}
int main()
{
    ll a,b,x,y,d;
    fin>>a>>b;
    cb=b;
    euclid(a,b,&x,&y,&d);
    while(x<0)
        x+=b;
    fout<<x;
    return 0;
}