Pagini recente » Cod sursa (job #3228183) | Cod sursa (job #845762) | Cod sursa (job #3134809) | Cod sursa (job #1703456) | Cod sursa (job #582273)
Cod sursa(job #582273)
#include <fstream>
#include <cstdlib>
using namespace std;
inline void gcd( int a, int b, int& x, int& y )
{
if( 0 == 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" );
ofstream out( "inversmodular.out" );
in>>a>>n;
gcd( a, n, x, y );
if( x < 0 )
x+=n;
out<<x<<'\n';
}