n, m, p = map(int, input().split()) a = list(map(int, input().split())) ans = 10 ** 9 s = set() t = 1 for k in a: t = 1 while k % p == 0: k //= p t += 1 if k == 1: continue x = 1 res = 0 while x <= m: x *= k res += t ans = min(ans, res) if ans != 10 ** 9: print(ans) else: print(-1)