Cod sursa(job #229069)

Utilizator MciprianMMciprianM MciprianM Data 9 decembrie 2008 07:23:39
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include<fstream>
using namespace std;
void cmmdc(int a, int b, long long &x, long long &y){
  if(b){
    cmmdc(b,a%b,x,y);
    long long aux=y;
    y=x-(a/b)*y;
    x=aux;
  }
  else
  {
        x=1;
        y=0;
  }
}
int main()
{
        int n, a;
        long long x, y;
        ifstream f("inversmodular.in");
        f>>a>>n;
        f.close();
        cmmdc(a,n,x,y);
        while(x<0)  x+=n;
        ofstream g("inversmodular.out");
        g<<x<<'\n';
        g.close();
        return 0;
}