Skip to content

Instantly share code, notes, and snippets.

@shoya140
Created October 2, 2012 02:37
Show Gist options
  • Save shoya140/3815857 to your computer and use it in GitHub Desktop.
Save shoya140/3815857 to your computer and use it in GitHub Desktop.
#encoding: utf-8
def is_perfect_number(number)
sum = 0
for i in 1 .. number
if number % i == 0 then
sum = sum + i
end
end
if sum == 2 * number then
return true
else
return false
end
end
print "数値を入力してください:"
input_number = gets.to_i
print "1から#{input_number}までには"
hit = 0
for i in 1 .. input_number
if is_perfect_number(i) == true then
print "#{i} "
hit = hit + 1
end
end
if hit == 0 then
puts "完全数はありません"
else
puts "という完全数があります"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment