Cod sursa(job #951491)

Utilizator costyrazvyTudor Costin Razvan costyrazvy Data 20 mai 2013 18:55:42
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>

using namespace std;

long long inv,ins,n,a;
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()
{
    ifstream f("inversmodular.in");
    ofstream g("inversmodular.out");
    f>>n>>a;
    gcd(inv,ins,a,n);
    if (inv <= 0)
       inv=n+inv%n;
    g<<inv<<'\n';
    f.close();
    g.close();
    return 0;
}