def pn(n) c = 0 i = 1 while c < 3 && i <= n c += 1 if n % i == 0 i += 1 end return n if c == 2 end def pna(n) a = [] n.times do |i| a << i+1 if pn(i+1) != nil end return a end p pna(gets.to_i).sum