Cod sursa(job #1206907)

Utilizator thesilverhand13FII Florea Toma Eduard thesilverhand13 Data 11 iulie 2014 14:44:16
Problema Invers modular Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
# include <fstream>
# include <cstring>
# include <algorithm>
# include <vector>

using namespace std;

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

int a, n, x, y, d;

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


int main(){
	f >> a >> n;
	euclid( a, n, d, x, y );
	//g << x << " " << y << "\n";
	if( d == 1 )
	g << x;
	else
		g << 0;
	return 0;
}