Skip to content

Instantly share code, notes, and snippets.

@ShenTengTu
Created December 24, 2017 10:28
Show Gist options
  • Save ShenTengTu/eb31d4c0d2b42ccf75df05732bee864d to your computer and use it in GitHub Desktop.
Save ShenTengTu/eb31d4c0d2b42ccf75df05732bee864d to your computer and use it in GitHub Desktop.
Get greatest common divisor(最大公因數) by Euclidean algorithm(輾轉相除法)
/*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