Pagini recente » Cod sursa (job #2266622) | Cod sursa (job #1040590) | Cod sursa (job #262194) | Cod sursa (job #1467730) | Cod sursa (job #460200)
Cod sursa(job #460200)
#include <cstdlib>
#include <fstream>
/*
*
*/
using namespace std;
inline void gcd( int a, int b, int& x, int& y )
{
if( 0 == b )
{
x=1;
y=0;
}
else {
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 );
x=( 0LL+x+N )%N;
ofstream out( "inversmodular.out" );
out<<x<<'\n';
return EXIT_SUCCESS;
}