You are viewing a single comment's thread. Return to all comments →
My python solution:
import sys import math nq = sys.stdin.readline() nq = nq.split(' ') n = int(nq[0]) q= int(nq[1]) A = sys.stdin.readline() A = A.split(' ') A= [int(i) for i in A] primes = [] m = 2 while len(primes) < q: flag = True for i in range(2, int(math.sqrt(m)) + 1): if m % i == 0: flag = False break if flag: primes.append(m) m += 1 for i in range(q): bi = [] ai = [] while len(A) > 0: val = A.pop() if val % primes[i] == 0: bi.append(val) else: ai.append(val) for b in reversed(bi): print b A = ai for a in reversed(A): print a
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 →
My python solution: