Cod sursa(job #2140210)

Utilizator tiberiu392Tiberiu Ungurianu tiberiu392 Data 23 februarie 2018 07:13:25
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include <fstream>

using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int inv=0, ins=0, a, n, aux;
void invmod(long long x, long long y, int a, int b)
{
    if ( !b )
        x=1, y=0;
    else
    {
        invmod( x, y, b, a%b);
        aux = x;
        x = y;
        y = aux-y*(a/b);
    }
}
int main()
{
    f >> a >> n;
    invmod( inv, ins, a, n);
    if ( inv <= 0)
        inv = n+inv%n;
    g << inv;
    return 0;
}