Pagini recente » Cod sursa (job #2041507) | Cod sursa (job #1217420) | Cod sursa (job #247176) | Cod sursa (job #2077142) | Cod sursa (job #615620)
Cod sursa(job #615620)
#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;
}