Created
December 8, 2016 17:57
-
-
Save yamadayuki/619b0eaa3a55b13a374348f9f60fed36 to your computer and use it in GitHub Desktop.
Greatest Common Divisor
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
// 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