Cod sursa(job #1402469)

Utilizator DobosDobos Paul Dobos Data 26 martie 2015 16:42:51
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
#define ll unsigned long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll
 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 = 0,y;
         euclid(a,n,x,y);
        if(x<=0)
            x = n + x%n;
        g<<x;


    return 0;
}