Advertisement
akass

Untitled

Oct 23rd, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. private void ExtendedEuclide(int a, int b, out int x, out int y, out int d)
  2.         {
  3.             //a*x+b*y=nod(a,b)=d
  4.             int q;//частное
  5.             x = 1;
  6.             y = 0;
  7.  
  8.             int x2 = 1;
  9.             int x1 = 0;
  10.             int y1 = 1;
  11.             int y2 = 0;
  12.  
  13.             int r;//остаток
  14.             while (b > 0)
  15.             {
  16.                 q = a / b;
  17.                 //r = a - q * b;
  18.                 r = a % b;
  19.                 x = x2 - q * x1;
  20.                 y = y2 - q * y1;
  21.                 a = b;
  22.                 b = r;
  23.                 x2 = x1; x1 = x; y2 = y; y1 = y;
  24.             }
  25.  
  26.             d = a;
  27.             x = x2;
  28.             y = y2;
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement