We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importsysn,q=input().strip().split(' ')n,q=[int(n),int(q)]number=list(map(int,input().strip().split(' ')))# get the prime numberslower=2upper=10000prime=[iforiinrange(lower,upper+1)ifall(i%j!=0forjinrange(2,i))]# set Two-dimensional arrayA=[[]foriinrange(q+1)]B=[[]foriinrange(q+1)]A[0]=number# pick up plates from A stackforiinrange(q):forjinrange(len(A[i])):n=A[i].pop()ifn%prime[i]==0:B[i].append(n)else:A[i+1].append(n)# print plates in Bforiinrange(len(B)):whileB[i]!=[]:print(B[i].pop(),)# print plates in Aforiinrange(len(A)):whileA[i]!=[]:print(A[i].pop(),)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Waiter
You are viewing a single comment's thread. Return to all comments →
Easy to understand python solution