Cod sursa(job #2590384)
Utilizator | Data | 27 martie 2020 20:11:31 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <iostream>
using namespace std;
struct str{
int d;
int x0;
int y0;
};
str euclid(int a, int b){
if(b==0)
return {a, 1, 0};
str d=euclid(b, a%b);
return {d.d, d.y0, d.x0-(a/b) * d.y0};
}
int main()
{
int a, n;
f>>a>>n;
str rez=euclid(a,n);
rez.x0 %=n;
while(rez.x0<0){
rez.x0+=n;}
g<<rez.x0;
return 0;
}