Cod sursa(job #3233824)
Utilizator | Data | 5 iunie 2024 01:29:48 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
long long x,y;
int a,b,c,n,i;
void euclid(int a, int b, long long &x, long long &y)
{
long long k;
if (b==0)
{
x=1;
y=0;
}
else
{
euclid(b,a%b,x,y);
k=x;
x=y;
y=k-(a/b)*y;
}
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d%d",&a,&n);
euclid(a,n,x,y);
while (x<0)
x=n+x%n;
printf("%d\n",x);
fclose(stdin);
fclose(stdout);
return 0;
}