Cod sursa(job #2331268)

Utilizator TheSeekerRobert Cristian Dobra TheSeeker Data 29 ianuarie 2019 13:47:45
Problema Invers modular Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>
using namespace std;

ifstream fin ("inversmodular.in");
ofstream fout("inversmodular.out");

int A,N,c,x,y,d;

void cmmdc(int a, int b, int &x, int &y) {
	if (b==0){
		d=a;
		x=1;
		y=0;
	}
	else{
		int x0,y0;
		cmmdc(b,a%b,x0,y0);
		x=y0;
		y=x0-(a/b)*y0;
	}
}

int main() {
	fin>>A>>N;
    cmmdc(A,N,x,y);
    if (c%d!=0)
        fout<<"0";
    else
        fout<<x;
	fin.close();
	fout.close();
	return 0;
}