We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents eb2cd79 + 46513c9 commit 897712dCopy full SHA for 897712d
Algorithms/Numeric/GreatestCommonDivisor.cs
@@ -9,25 +9,22 @@ public static class GreatestCommonDivisor
9
/// </summary>
10
public static int FindGCDEuclidean(int a, int b)
11
{
12
+ int t = 0;
13
+
14
a = Math.Abs(a);
15
b = Math.Abs(b);
16
17
if (a == 0)
18
return b;
19
if (b == 0)
20
return a;
- if (a == b)
- return a;
21
-
22
- return Euclidean(a, b);
23
- }
24
25
- private static int Euclidean(int a, int b)
26
- {
27
- if (b == 0)
28
29
30
- return Euclidean(b, a % b);
+ while (a % b != 0) {
+ t = b;
+ b = a % b;
+ a = t;
+ }
+ return b;
31
}
32
33
/// <summary>
0 commit comments