Cod sursa(job #1144596)

Utilizator c0rn1Goran Cornel c0rn1 Data 17 martie 2014 12:45:09
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <stdio.h>
#define LL long long

using namespace std;

void euclid(LL a, LL b, LL &x, LL &y)
{
    if (!b)
    {
        x=1;
        y=0;
    }
    else
    {
        LL x0, y0;
        euclid(b, a%b, x0, y0);
        x=y0;
        y=x0-(a/b)*y0;
    }
}

void sol()
{
    LL a, b, d, x, y;
    scanf("%lld %lld", &a, &b);
    euclid(a, b, x, y);
    for (; x<0; x+=b);
    printf("%d", x);
}

int main()
{
    freopen("inversmodular.in", "r", stdin);
    freopen("inversmodular.out", "w", stdout);
    sol();
    return 0;
}