Pagini recente » Istoria paginii runda/avram_vara_1/clasament | Cod sursa (job #707530) | Cod sursa (job #2583045) | Cod sursa (job #342884) | Cod sursa (job #1584887)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(long long &x,long long &y,int a,int b)
{
if(b==0)
{
x=1;
y=0;
}
else
{
long long x0,y0;
gcd(x0,y0,b,a%b);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
int n,m;
long long x=0,y;
fin>>n>>m;
gcd(x,y,n,m);
if(x<=0) x=n+x%n;
fout<<x;
}