Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (a == int.MinValue || b == int.MinValue || IsMinValue(other))
- {
- throw new ArgumentOutOfRangeException(nameof(a), "Argument a out of range");
- }
- if (a == 0 && b == 0 && AllZeros(other))
- {
- throw new ArgumentException("Argument's can't be 0 at the same time", nameof(a));
- }
- a = Math.Abs(a);
- b = Math.Abs(b);
- AbsArray(other);
- for (int i = 0; i < other.Length; i++)
- {
- if (a == 0)
- {
- return GetGcdByStein(b, other[i]);
- }
- else if (b == 0)
- {
- return GetGcdByStein(a, other[i]);
- }
- else if (a == b)
- {
- return GetGcdByStein(a, other[i]);
- }
- else if (a % 2 == 0 && b % 2 == 0)
- {
- return GetGcdByStein(2 * GetGcdByStein(a / 2, b / 2), other[i]);
- }
- else if (a % 2 == 0 && b % 2 != 0)
- {
- return GetGcdByStein(GetGcdByStein(a / 2, b), other[i]);
- }
- else if (a % 2 != 0 && b % 2 == 0)
- {
- return GetGcdByStein(GetGcdByStein(a, b / 2), other[i]);
- }
- else if (a > b)
- {
- return GetGcdByStein(GetGcdByStein((a - b) / 2, b), other[i]);
- }
- else
- {
- return GetGcdByStein(GetGcdByStein((b - a) / 2, a), other[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement