from heapq import heappop,heappush def main1(n,m,p,a): d={} mxv=0 for x in a: mxv=max(mxv,x) cnt=1 while x%p==0: cnt+=1 x//=p if x==1:continue if cnt in d:d[cnt]=max(d[cnt],x) else:d[cnt]=x if mxv>m:return 1 if len(d)==0:return -1 todo=[[0,1]] costary=[0]*1000 costary[0]=1 ans=float('inf') while todo: c,v=heappop(todo) if costary[c]>v:continue if v>m: ans=min(ans,c) continue if v*mxv>m: ans=min(ans,c+1) continue for key,value in d.items(): if costary[c+key]