Cod sursa(job #1181405)

Utilizator SagunistuStrimbu Alexandru Sagunistu Data 2 mai 2014 17:16:56
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <iostream>
#include <fstream>

using namespace std;

void gcd(long long &x, long long &y, long long a,long long b)
{
    if(b==0)
    {
        x=1;
        y=0;
    }
    else
    {
        gcd(x,y,b,a%b);
        long long aux=x;
        x=y;
        y=aux-y*(a/b);
    }
}

int main()
{
    ifstream fin("inversmodular.in");
    ofstream fout("inversmodular.out");
    long long a,n,x,y;
    fin>>a>>n;
    gcd(x,y,a,n);
    if(x<0)
        x=n+x%n;
    fout<<x;
    return 0;
}