Cod sursa(job #1806816)

Utilizator Mircea_DonciuDonciu Mircea Mircea_Donciu Data 15 noiembrie 2016 18:19:39
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <fstream>

using namespace std;
int a,n;
long long inv,ins;
void gcd(long long &x, long long &y, int a, int b)
{
     if(!b)
     {
         x=1;
         y=0;
     }
     else
     {
         gcd(x,y,b,a%b);
         long long aux=x;
         x=y;
         y=aux-y*(a/b);
     }
}
int main()
{
    ifstream f("inversmodular.in");
    ofstream g("inversmodular.out");
    f>>a>>n;
    gcd(inv,ins,a,n);
    if(inv<=0)
       inv=n+inv%n;
    g<<inv<<'\n';
    f.close(); g.close();
    return 0;
}