Cod sursa(job #1402461)

Utilizator DobosDobos Paul Dobos Data 26 martie 2015 16:39:45
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <iostream>
#include <fstream>
#define ll unsigned long long
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int euclid(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
        x = 1,y = 0;
        else
        {
    euclid(b, a % b,x,y);
    ll aux = x;
    x = y;
    y = aux - (a / b) * y;
        }
}

int main()
{
    ll a,n;

        f>>a>>n;
        ll x,y;
         euclid(a,n,x,y);
        if(x<=0)
            x = n + x%n;
        g<<x;


    return 0;
}