Pagini recente » Cod sursa (job #1115163) | Cod sursa (job #109231) | Cod sursa (job #1910405) | Cod sursa (job #1721992) | Cod sursa (job #449051)
Cod sursa(job #449051)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on May 5, 2010, 3:12 PM
*/
#include <cstdlib>
#include <fstream>
/*
*
*/
using namespace std;
inline void gcd( int a, int b, int& x, int& y )
{
if( !b )
x=1, y=0;
else {
int x0, y0;
gcd( b, a%b, x0, y0 );
x=y0;
y=x0-(a/b)*y0;
}
}
int main(int argc, char** argv)
{
int A, N, x, y;
ifstream in( "inversmodular.in" );
ofstream out( "inversmodular.out" );
in>>A>>N;
gcd( A, N, x, y );
out<<( ( 0LL+x%N+N )%N )<<'\n';
return (EXIT_SUCCESS);
}