Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void ExtendedEuclide(int a, int b, out int x, out int y, out int d)
- {
- //a*x+b*y=nod(a,b)=d
- int q;//частное
- x = 1;
- y = 0;
- int x2 = 1;
- int x1 = 0;
- int y1 = 1;
- int y2 = 0;
- int r;//остаток
- while (b > 0)
- {
- q = a / b;
- //r = a - q * b;
- r = a % b;
- x = x2 - q * x1;
- y = y2 - q * y1;
- a = b;
- b = r;
- x2 = x1; x1 = x; y2 = y; y1 = y;
- }
- d = a;
- x = x2;
- y = y2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement