Created
December 24, 2017 10:28
-
-
Save ShenTengTu/eb31d4c0d2b42ccf75df05732bee864d to your computer and use it in GitHub Desktop.
Get greatest common divisor(最大公因數) by Euclidean algorithm(輾轉相除法)
This file contains 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
/*greatest common divisor(最大公因數)*/ | |
function gcd(x,y){ | |
//Euclidean algorithm(輾轉相除法) | |
if(y) | |
while((x%=y) && (y%=x)){} | |
return x+y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment