#!/usr/bin/env ruby
#-*- coding:utf-8 -*-

i = 1
a = 1
yakusu1=[]
yakusu2=[]
koyakusu = []

puts"最大公約数を出します"
puts"1つ目の数字を入力してください"
suzi1 = gets.to_i
puts"2つ目の数字を入力してください"
suzi2 = gets.to_i

while i <= suzi1
  x = suzi1 % i
  if x == 0
    yakusu1<< i
  end
  i +=1
end

while a <= suzi2
  y = suzi2 % a
  if y == 0
    yakusu2 << a
  end
  a +=1
end

i = 0

while i != yakusu1.length
  yakusu2.each do |n|
    if yakusu1[i] == n
      koyakusu << n
    end
  end
  i +=1
end

if koyakusu.reverse[0] != nil
  printf("%dと%dの最大公約数は%dです\n",suzi1,suzi2,koyakusu.reverse[0])
else
  printf("%dと%dに公約数はありません\n",suzi1,suzi2)
end
