P = 10**9+7 N = gets.to_i A = gets.split.map &:to_i Q = gets.to_i PLR = $<.map{|s| s.split.map &:to_i } cumul = [mul = 1] + A.map{|a| mul *= (a == 0 ? P : a) } # p cumul PLR.each{|p, l, r| mul = cumul[r] / cumul[l-1] if mul % P == 0 || mul % p == 0 puts "Yes" else puts "NO" end }