Cod sursa(job #1412955)

Utilizator DobosDobos Paul Dobos Data 1 aprilie 2015 17:49:16
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
#define ll  long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");

void euclid(int a, int b, ll &x, ll &y)

{
    if (!b)
        x = 1,y = 0;
        else
        {
    euclid(b, a % b,x,y);
    ll aux = x;
    x = y;
    y = aux -  y*(a / b) ;
        }
}

int main()
{
    int a,n;

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


    return 0;
}