Cod sursa(job #2040824)

Utilizator vlad_schillerSchiller Vlad Radu vlad_schiller Data 16 octombrie 2017 16:40:31
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");

void cmmdc(int a,int b,int &k,int &l)
{
    if(b==0)
    {
        k=1;
        l=0;
    }
    else
    {
        int k0,l0;
        cmmdc(b,a%b,k0,l0);
        l = k0 - l0 * (a / b);
        k = l0;
    }
}

int main()
{
    int a,n,k,l;
    f>>a>>n;
    cmmdc(a,n,k,l);
    while(k<0)
        k+=n;
    g<<k;
    return 0;
}