Cod sursa(job #2264417)

Utilizator PredescuSebastianIonPredescu Sebastian Ion PredescuSebastianIon Data 20 octombrie 2018 09:13:04
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>

using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,mod,x0,x1,r0,r1,x,r,q;
int main()
{
    f>>a>>mod;
    x0=1;
    x1=0;
    r0=a;
    r1=mod;
    while(r1!=0)
    {
        r=r0%r1;
        q=r0/r1;
        x=x0-q*x1;
        x0=x1;
        x1=x;
        r0=r1;
        r1=r;
    }
    if(x0<0)x0=x0+mod;
    g<<x0<<'\n';
    return 0;
}