Advertisement
yahorrr

Untitled

Apr 13th, 2022
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1.  if (a == int.MinValue || b == int.MinValue || IsMinValue(other))
  2.             {
  3.                 throw new ArgumentOutOfRangeException(nameof(a), "Argument a out of range");
  4.             }
  5.  
  6.             if (a == 0 && b == 0 && AllZeros(other))
  7.             {
  8.                 throw new ArgumentException("Argument's can't be 0 at the same time", nameof(a));
  9.             }
  10.  
  11.             a = Math.Abs(a);
  12.             b = Math.Abs(b);
  13.             AbsArray(other);
  14.  
  15.             for (int i = 0; i < other.Length; i++)
  16.             {
  17.                 if (a == 0)
  18.                 {
  19.                     return GetGcdByStein(b, other[i]);
  20.                 }
  21.                 else if (b == 0)
  22.                 {
  23.                     return GetGcdByStein(a, other[i]);
  24.                 }
  25.                 else if (a == b)
  26.                 {
  27.                     return GetGcdByStein(a, other[i]);
  28.                 }
  29.                 else if (a % 2 == 0 && b % 2 == 0)
  30.                 {
  31.                     return GetGcdByStein(2 * GetGcdByStein(a / 2, b / 2), other[i]);
  32.                 }
  33.                 else if (a % 2 == 0 && b % 2 != 0)
  34.                 {
  35.                     return GetGcdByStein(GetGcdByStein(a / 2, b), other[i]);
  36.                 }
  37.                 else if (a % 2 != 0 && b % 2 == 0)
  38.                 {
  39.                     return GetGcdByStein(GetGcdByStein(a, b / 2), other[i]);
  40.                 }
  41.                 else if (a > b)
  42.                 {
  43.                     return GetGcdByStein(GetGcdByStein((a - b) / 2, b), other[i]);
  44.                 }
  45.                 else
  46.                 {
  47.                     return GetGcdByStein(GetGcdByStein((b - a) / 2, a), other[i]);
  48.                 }
  49.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement