Cod sursa(job #1916740)

Utilizator AndreRageBota Claudiu AndreRage Data 9 martie 2017 10:15:56
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int a,n;
long long inv=0,ins;
void invers(long long x, long long y, int a, int b)
{
    if(b==0)
    {
        x=1;
        y=0;
    }
    else
    {
        long long au;
        invers(x,y,b,a%b);
        au=x;
        x=y;
        y=au-y*(a/b);
    }
}
int main()
{
    in>>a>>n;
    invers(inv,ins,a,n);
    if(inv<=0)
        inv=n+inv%n;
    out<<inv;


    return 0;
}