import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val m = nextLong() val p = nextLong() val a = Array(n) { nextLong() } val b = a.copyOf() val c = Array(n) { 0 } for (i in 0 until n) { while (b[i] % p == 0L) { b[i] /= p c[i]++ } } val max_a = a.max()!! val max_b = b.max()!! if (max_b == 1L && max_a < m) { println(-1) return } val stack = Stack() stack.push(1) val map = mutableMapOf() map[1] = 0 var ans = Int.MAX_VALUE while (stack.isNotEmpty()) { val now = stack.pop() if (now * max_a > m) { ans = min(ans, map[now]!! + 1) } else { for (i in 0 until n) { val nxt = now * b[i] if (!map.containsKey(nxt)) stack.push(nxt) map[nxt] = min(map[nxt] ?: Int.MAX_VALUE, map[now]!! + c[i] + 1) } } } println(ans) } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine()!! fun nextDouble() = next().toDouble() // endregion