Mai intai trebuie sa te autentifici.

Cod sursa(job #1609933)

Utilizator NaritaAndreiNarita Andrei NaritaAndrei Data 23 februarie 2016 10:19:12
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <stdio.h>

using namespace std;
FILE *f,*g;
long long iv(long long a,long long b,long long &x,long long &y)
{
    int aux;
    if(b==0)
    {x=1; y=0;}
    else
    {
        iv(b,a%b,x,y);
        aux=x;
        x=y;
        y=aux-a/b*y;
    }
}
int main()
{
    long long a,b,x,y;
    f=fopen("inversmodular.in","r");
    g=fopen("inversmodular.out","w");
    fscanf(f,"%lld %lld",&a,&b);
    iv(a,b,x,y);
    while(x<0) x=x+b;
    fprintf(g,"%lld",x);
    fclose(f);
    fclose(g);
    return 0;
}