Mai intai trebuie sa te autentifici.
Cod sursa(job #582273)
| Utilizator | Data | 15 aprilie 2011 10:00:58 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#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';
}
