Enter a number and return true if it is a prime number, false if it is not a prime number.
while str = STDIN.gets
break if str.chomp == "exit"
n=str.to_i
count=0
for i in 1..n+1 do
d=n%i
if d==0 then
count+=1
end
end
if count==2 then
print("true")
else
print("false")
end
puts "\n"
end
October 20, 2020
Recommended Posts