Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created March 4, 2019 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/dcda64240852bfdd4783b9c5a6e79dec to your computer and use it in GitHub Desktop.
Save whatalnk/dcda64240852bfdd4783b9c5a6e79dec to your computer and use it in GitHub Desktop.
AtCoder ABC #120 B. K-th Common Divisor
a, b, k = gets.chomp.split(" ").map(&:to_i)
ret = []
c = [a, b].min
1.upto(c) do |i|
if a % i == 0 && b % i == 0
ret << i
end
end
puts ret.reverse[k - 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment