Cod sursa(job #1246216)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 20 octombrie 2014 19:38:31
Problema Invers modular Scor 50
Compilator c Status done
Runda Arhiva educationala Marime 0.58 kb
#include <stdio.h>
void euclid(long long a, long long b, long long *x, long long *y){
    long long x0, y0;
    if(b==0){
        *x=1;
        *y=0;
        return ;
    }
    euclid(b, a%b, &x0, &y0);
    *x=y0;
    *y=x0-((a/b)*y0);
}
int main(){
    long long x, y, a, n;
    FILE *fin, *fout;
    fin=fopen("inversmodular.in", "r");
    fout=fopen("inversmodular.out", "w");
    fscanf(fin, "%lld%lld", &a, &n);
    euclid(a, n, &x, &y);
    if(x<0){
        x=x+(x%n);
    }
    fprintf(fout, "%lld\n", x);
    fclose(fin);
    fclose(fout);
    return 0;
}