Cod sursa(job #1428327)

Utilizator cristibogdanPatrascu Cristian cristibogdan Data 4 mai 2015 08:58:34
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>

using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int n ,a,b,i,d,c,q,r;

 void invmod(long long &x, long long &y, int a, int b)
{
     if (!b)
         x = 1, y = 0;
     else
     {
         invmod(x, y, b, a % b);
         long long aux = x;
         x = y;
         y = aux - y * (a / b);
     }
}


int main()
{
long long x,y;
    f>>a>>b;
    x=0;

invmod(x,y,a,b);
if (x<= 0)
       x= b+x%b;
g<<x;

    return 0;
}