Pagini recente » Cod sursa (job #1257037) | Cod sursa (job #507325) | Cod sursa (job #1194913) | Cod sursa (job #697181) | Cod sursa (job #2152421)
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n;
int gcdExtended(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
int x0,y0;
int gcd=gcdExtended(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
return gcd;
}
void modularInverse(int a,int n)
{
int x,y;
int gcd=gcdExtended(a,n,x,y);
int res=(x%n+n)%n;
g<<res;
}
int main()
{
f>>a>>n;
modularInverse(a,n);
return 0;
}