Cod sursa(job #460200)
Utilizator | SAlexandru BitOne | Data | 1 iunie 2010 16:17:49 |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#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;
}