Cod sursa(job #1451580)

Utilizator iulianrotaruRotaru Gheorghe-Iulian iulianrotaru Data 17 iunie 2015 18:58:58
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>
#define ll long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int A,N;
void gcd(ll &x,ll &y,ll a,ll b)
{
    if(!b) {x=1; y=0;}
    else
    {
        gcd(x,y,b,a%b);
        ll aux=x;
        x=y;
        y=aux-y*(a/b);
    }
}
int main()
{
    f>>A>>N;
    ll cal=0,ver;
    gcd(cal,ver,A,N);
    if(cal<=0) cal=N+cal%N;
    g<<cal;
    g.close();
    return 0;
}