Cod sursa(job #2186364)

Utilizator VladG26Ene Vlad-Mihai VladG26 Data 25 martie 2018 15:30:37
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;
void invmod(ll a,ll b,ll &x,ll &y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return;
    }
    ll x0,y0;
    invmod(b,a%b,x0,y0);
    x=y0;
    y=x0-(a/b)*y0;
}
int main()
{
    freopen("inversmodular.in","r",stdin);
    freopen("inversmodular.out","w",stdout);
    ll a,n,x,y;
    scanf("%lld%lld",&a,&n);
    invmod(a,n,x,y);
    if(x<=0)
        x=n+x;
    printf("%lld",x);
    return 0;
}