Cod sursa(job #2476783)

Utilizator Vladv01Vlad Vladut Vladv01 Data 19 octombrie 2019 11:28:07
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <iostream>
#include <fstream>

using namespace std;


ifstream f("inversmodular.in");
ofstream g("inversmodular.out");


void euclidext( long long a ,long long b , long long &x,long long &y)
{

   if(!b)
   {
       x=1;
       y=0;
       return;
    }
    euclidext(b,a%b,x,y);
    long long aux=x;
    x=y;
    y=aux -(a/b)*y;
}


int main()
{
   long long n,a,b,c,x,y,d;
   f>>a>>b;
   euclidext(a,b,x,y);
   if(x<0)
    g<<x+n;
   else
    g<<x;
    return 0;
}