Cod sursa(job #1496974)

Utilizator Burbon13Burbon13 Burbon13 Data 5 octombrie 2015 21:36:35
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <cstdio>

using namespace std;

void euclid(int a, int b, long long& x, long long& y){
    if(not b){
        x = 1;
        y = 0;
        return;
    }
    euclid(b,a%b,x,y);
    long long aux = x;
    x = y;
    y = aux - (a/b)*y;
}

int main(){
    freopen("inversmodular.in", "r", stdin);
    freopen("inversmodular.out", "w", stdout);
    int n,a;
    scanf("%d %d", &n, &a);
    long long x, y;
    euclid(n,a,x,y);
    if(x < 0)
        x = n + x % n;
    printf("%d\n", x);

    return 0;
}