N, M, P = map(int, input().split()) A = map(int, input().split()) def solve(a): x = 1 ct = 0 div = 1 while not a % P: div += 1 a //= P if a == 1: return -1 while x <= M: x *= a ct += div return ct ans = float('inf') for a in A: s = solve(a) if s != -1: ans = min(ans, s) print(ans if ans != float('inf') else -1)