Cod sursa(job #311319)

Utilizator sandyxpSanduleac Dan sandyxp Data 3 mai 2009 11:41:30
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <fstream>
using namespace std;

#define NUME "inversmodular"
ifstream fi(NUME".in");
ofstream fo(NUME".out");

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

int main()
{
    long long x, y;
    int A, N;
    fi >> A >> N;
    gcd(x, y, A, N);
    //while (
    fo << x % N << endl;
    return 0;
}