fun main(args: Array) { val table = BooleanArray(2001, {true}) val primes: MutableList = mutableListOf() for (i in 2..2000) { if (table[i]) { primes.add(i) for (j in 2*i..2000 step i) { table[j] = false } } } val rd = Reader() val N = rd.int() val A = IntArray(N) val zero = IntArray(N+1) for (i in 0..N-1) { A[i] = rd.int() zero[i+1] = zero[i] + (if (A[i] == 0) 1 else 0) } val Q = rd.int() val P = IntArray(Q) val L = IntArray(Q) val R = IntArray(Q) for (i in 0..Q-1) { P[i] = rd.int() L[i] = rd.int() - 1 R[i] = rd.int() } val ruiseki = IntArray(N+1) val kotae = BooleanArray(Q, {true}) for (p in primes) { ruiseki.fill(0) for (i in 0..N-1) { ruiseki[i+1] = ruiseki[i] if (A[i] == 0) continue while (A[i] % p == 0) { ruiseki[i+1]++; A[i] /= p } } for (i in 0..Q-1) { if (zero[R[i]] - zero[L[i]] > 0) { P[i] = 1 continue } var k = 0 while (P[i] % p == 0) { P[i] /= p k++ } if (ruiseki[R[i]] - ruiseki[L[i]] < k) kotae[i] = false } } for (i in 0..Q-1) { if (P[i] != 1) kotae[i] = false println(if (kotae[i]) "Yes" else "NO") } } class Reader { var buf: ByteArray = ByteArray(5000000) var k: Int = 0 var n: Int = 0 init { check() } private fun check() { if (k == n) { n = System.`in`.read(buf) k = 0 } } private fun peek(): Byte { return buf[k] } private fun next() { k++ check() } fun long(): Long { var ans: Long = 0 while ('0'.toByte() > peek()) next() while ('0'.toByte() <= peek()) { ans = ans * 10 + (peek() - '0'.toLong()) next() } return ans } fun int(): Int { return long().toInt() } }