Cod sursa(job #3005076)
| Utilizator | Data | 16 martie 2023 19:11:28 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void euclid(int a , int b ,int & x ,int & y)
{
if(b == 0)
{
x = 1, y = 1;
}
else
{
int x1 , y1;
euclid(b , a % b , x1 , y1);
x = y1;
y = x1 - a / b * y1;
}
}
long long int A,N;
int main()
{
fin>>A>>N;
int X,Y;
euclid(A, N , X ,Y);
while(X<0)
X+=N;
fout<<X;
return 0;
}
