Skip to content

Instantly share code, notes, and snippets.

@yamadayuki
Created December 8, 2016 17:57
Show Gist options
  • Save yamadayuki/619b0eaa3a55b13a374348f9f60fed36 to your computer and use it in GitHub Desktop.
Save yamadayuki/619b0eaa3a55b13a374348f9f60fed36 to your computer and use it in GitHub Desktop.
Greatest Common Divisor
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B
// Test Case
// 54 20 => 2
// 147 105 => 21
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split(' ').map(Number);
function gcd(x, y) {
if (y === 0) {
console.log(x);
} else {
gcd(y, x % y);
}
}
gcd(input[0], input[1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment