Pagini recente » Cod sursa (job #1070745) | Cod sursa (job #1683099) | Cod sursa (job #2001839) | Cod sursa (job #2720554) | Cod sursa (job #2561231)
#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
ifstream fin( "inversmodular.in" );
ofstream fout( "inversmodular.out" );
void fast()
{
cin.tie( 0 );
ios_base::sync_with_stdio( 0 );
}
int a,b;
void invers( int a, int b, int &x, int &y )
{
if( !b )
{
x = 1;
y = 0;
return;
}
int x0, y0;
invers( b, a % b, x0, y0 );
x = y0;
y = x0 - y0 * ( a / b );
}
int main()
{
fast();
fin >> a >> b;
int x, y;
invers( a, b, x, y );
while( x < 0 )
x = ( x + b ) % b;
fout << x;
return 0;
}