Created
June 16, 2020 01:47
-
-
Save 3014zhangshuo/58f646cebe85e21caf3fdeef9d974d66 to your computer and use it in GitHub Desktop.
Euclid's algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int gcd(int p, int q) | |
{ | |
if (q == 0) return p; | |
int r = p % q; | |
return gcd(q, r); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compute the greatest common divisor of two nonnegative integers p and q as follows: If q is 0, answer is p. If not, divide p by q and take the remainder r. The answer is the greatest common divisor of q and r.