def sieve_of_eratosthenes(max) arr=(2..max).to_a (2..Math::sqrt(max)).each do |i| arr.delete_if {|a|a % i == 0 && a!=i} end arr end games=[] gets.to_i.times{ games << gets.to_i } primes = sieve_of_eratosthenes(games.max) games.map{|x| if x < 2 puts "Bob" else puts primes.select{|y|y<=x}.count%2==0 ? "Bob" : "Alice" end }