Cod sursa(job #1526904)

Utilizator andreeacozma95Cozma Andreea andreeacozma95 Data 17 noiembrie 2015 17:04:20
Problema Invers modular Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.57 kb
#include <stdio.h>
#include <stdlib.h>
int n,a;

void euclidExtins(int a, int b, long long *x, long long *y)
{
    if (b==0)
    {
        *x=1;
        *y=0;
    }
    else
    {
        long long x0,y0;
        euclidExtins(b,a%b,&x0,&y0);
        *x=y0;
        *y=x0-(a/b)*y0;
    }
}

int main()
{
    long long x,y;
    FILE *f=fopen("inversmodular.in", "r");
    FILE *g=fopen("inversmodular.out", "w");
    fscanf(f,"%d%d",&a,&n);

    euclidExtins(a,n,&x,&y);

    if (x<=0)
        x=n+x%n;

    fprintf(g,"%lld\n",x);
    return 0;
}