require "prime" $memo = { 0 => [[0, 1]] } def f(n) $memo[n] ||= n.prime_division end 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 } $cusum = [primes = Hash.new(0)] + A.map{|a| primes = primes.dup f(a).each{|k, v| primes[k] += v } primes } PLR.each{|p, l, r| # p f(p) # puts [$cusum[r], $cusum[l-1]] if $cusum[r][0] - $cusum[l-1][0] > 0 puts "Yes" elsif f(p).all?{|k, v| $cusum[r][k] - $cusum[l-1][k] >= v } puts "Yes" else puts "NO" end }