Pagini recente » Cod sursa (job #1420969) | Cod sursa (job #654637) | Cod sursa (job #532275) | Cod sursa (job #2473572) | Cod sursa (job #437289)
Cod sursa(job #437289)
/*
* File: main.cpp
* Author: VirtualDemon
*
* Created on April 9, 2010, 4:01 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;
return;
}
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 );
x=( 0LL+N+x%N )%N;
out<<x<<'\n';
return EXIT_SUCCESS;
}