Cod sursa(job #615620)

Utilizator BitOneSAlexandru BitOne Data 10 octombrie 2011 12:53:28
Problema Invers modular Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include <fstream>
#include <cstdlib>

using namespace std;
inline void gcd( int a, int b, int& x, int& y )
{
	if( !b )
	{
		x=1;
		y=0;
		return;
	}
	int x0, y0;
	gcd( b, a%b, x0, y0 );
	x=y0;
	y=x0-(a/b)*y0;
}
int main( void )
{
	int A, N, x, y;
	ifstream in( "inversmodular.in" );
	in>>A>>N;
	gcd( A, N, x, y );
	ofstream out( "inversmodular.out" );
	out<<((x+N)%N)<<'\n';
	return EXIT_SUCCESS;
}