Cod sursa(job #2182557)

Utilizator 3DwArDPauliuc Edward 3DwArD Data 22 martie 2018 14:42:00
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll A,N;
void gcd(int a,int b,int &x,int &y){
    if(b==0)x=1,y=0;
    else{
        gcd(b,a%b,x,y);
        ll aux=x;
        x=y;
        y=aux-y*(a/b);
    }
}
int main()
{
    f>>A>>N;
    int x,y;
    gcd(A,N,x,y);
    if(x<0)
        x=N+x%N;
        g<<x;
    return 0;
}