import math def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 M = int(data[idx]) idx += 1 P = int(data[idx]) idx += 1 A = list(map(int, data[idx:idx+N])) a_list = [] for ai in A: e = 0 temp = ai while temp % P == 0 and temp != 0: e += 1 temp = temp // P a = temp if a > 1: a_list.append((a, e)) if not a_list: print(-1) return min_steps = float('inf') for a, e in a_list: steps = 0 current = 1 while current <= M: current *= a steps += 1 total_cost = steps * (1 + e) if total_cost < min_steps: min_steps = total_cost print(min_steps) if __name__ == '__main__': main()