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

def yakusu(x)
  i = 1
  yaku =[]
  while i <= x
    y = x % i
    if y == 0
      yaku << i
    end
    i += 1
  end
  return yaku
end

def koyaku(x,y)
  a = 0
  koyakusu = []
  while a != x.length
    y.each do |n|
    if x[a] == n
      koyakusu << n
    end
  end
  a += 1
  end
  return koyakusu
end

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

yakusu1 = yakusu(suzi1)
yakusu2 = yakusu(suzi2)
koyakusu = koyaku(yakusu1,yakusu2)

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