Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 14, 2018 07:42
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/35d0b984fe6eb213b2393f99f349fd74 to your computer and use it in GitHub Desktop.
Save whatalnk/35d0b984fe6eb213b2393f99f349fd74 to your computer and use it in GitHub Desktop.
AtCoder AGC 028 A
n, m = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
t = gets.chomp
l = n.lcm(m)
x = Hash.new(nil)
n.times do |i|
j = i * (l / n)
x[j] = s[i]
end
m.times do |i|
j = i * (l / m)
if !x[j].nil?
if x[j] != t[i]
puts -1
exit
end
end
end
puts l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment