Cod sursa(job #541717)

Utilizator PsychoRoAlex Buicescu PsychoRo Data 25 februarie 2011 13:33:27
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include<fstream.h>
#include <stdio.h>
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
void gcd(long long &x, long long &y, int a, int b)  
{  
	long long aux;
     if (!b)  
         x = 1, y = 0;  
     else  
     {             
         gcd(x, y, b, a % b);
         aux = x;
         x = y;
         y = aux - y * (a / b);
     }
}

int main()
{
    long long inv = 0, ins;
    fin>>A>>N;
    gcd(inv, ins, A, N);
    if (inv <= 0)
       inv = N + inv % N;
      fout<<inv;
    return 0;
}

/*date.in: 5 7
date.out: 3 // 5*3=15/7=2, restul 1*/