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