Problem:


Score : 400 points

Problem Statement

There are N empty boxes arranged in a row from left to right.
The integer i is written on the i-th box from the left (1 \leq i \leq N).

For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.

We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:

For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.

Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

a_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If a good set of choices does not exist, print -1.

If a good set of choices exists, print one such set of choices in the following format:

M
b_1 b_2 ... b_M

where M denotes the number of boxes that will contain a ball, and b_1,\ b_2,\ ...,\ b_M are the integers written on these boxes, in any order.

Sample Input 1

3
1 0 0

Sample Output 1

1
1

Consider putting a ball only in the box with 1 written on it.

There are three boxes with multiples of 1 written on them: the boxes with 1, 2, and 3. The total number of balls contained in these boxes is 1.

There is only one box with a multiple of 2 written on it: the box with 2. The total number of balls contained in these boxes is 0.

There is only one box with a multiple of 3 written on it: the box with 3. The total number of balls contained in these boxes is 0.

Thus, the condition is satisfied, so this set of choices is good.

Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Putting nothing in the boxes can be a good set of choices.



Sample input:
3
1 0 0


Sample output:
1
1

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()] 
ls = np.array(a)

for ind in range(int(n/2), 0, -1):
    tmp = list(range(2*ind-1, n, ind))
    if a[ind-1] == ls[tmp].sum()%2:
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        
print(sum(ls))
ans = np.where(ls==1)[0] + 1
ans = list(ans.astype(str))
print(' '.join(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
zeros = np.zeros(N)
index = np.arange(1, N + 1)
middle = int(N / 2) + 1

for i, e in zip(a[::-1], index[::-1]):
    if e >= middle:
        zeros[e - 1] = i
    else:
        if sum(zeros[index % e == 0]) % 2 != i:
            zeros[e - 1] = 1

print(int(sum(zeros)))

for i, e in zip(zeros, index):
    if i == 1:
        print(e, end=" ")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
output = [0]*N

output[N//2:]=A[N//2:]

t = N//2-1
for j in range(N//2):
    for i in range(N//(t+1)-1):
        output[t]= (output[t]+output[(t+1)*(i+2)-1])%2
    output[t]=int(output[t] != A[t])
    t -= 1

ans = ""
flag = 0
for j in range(N):
    if output[j]==1:
        ans += str(j+1) + " "
        flag += 1
print(flag)
if flag > 0:
    ans = ans[:-1]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
zeros = np.zeros(N)
index = np.arange(1, N + 1)
middle = int(N / 2) + 1

for i, e in zip(a[::-1], index[::-1]):
    if e >= middle:
        zeros[e - 1] = i
    else:
        if sum(zeros[index % e == 0]) % 2 == i:
            pass
        else:
            zeros[e - 1] = 1

M = sum(zeros)
print(int(M))

for i, e in zip(zeros, index):
    if i == 1:
        print(e, end=" ")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ax = list(map(int,input().split()))
 

boxin = []
for cnt in range(N, 0, -1):
    a = ax[cnt-1]
    
    i = 2
    memo_cnt = 0
    while 1:
        test_val = i * cnt
        if test_val > N:
            break
        if test_val in boxin:
            memo_cnt += 1
        i += 1
    if a != memo_cnt % 2:
        boxin.append(cnt)

 
box = len(boxin)
print(box)
if box != 0:
    boxin.reverse()
    print(' '.join(map(str, boxin)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
li=list(map(int,input().split()))

ans=[]
for i in range(n-1,n//2-1,-1):
  if li[i]==1:
    ans.append(i+1)

for i in range(n//2,0,-1):
  count=0
  for j in ans:
    if j%i==0:
      count+=1
  if count%2!=li[i-1]:
    ans.append(i)
ans.reverse()
print(len(ans))
L=[str(a) for a in ans]
L=" ".join(L)
if len(L)!=0:
  print(L)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ai = [int(x) for x in input().split()]
bn = [0] * n
cn = [0] * n

for i in range(0,n):
    j = n - 1 - i
    if (n//(j+1)<1):
        bn[j] = ai[j]
    else:
        bn[j] = (cn[j] + ai[j]) % 2

    if bn[j] == 1 and not(n//(j+1) < 1):
        for k in range(0,((j+1)//2)+1):
            if (j+1)%(k+1) == 0:
                cn[k] += 1

m = sum(bn)
print(m)
for i in range(0,n):
    if bn[i] == 1:
        print(i+1, end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()] 

a = np.array(a)
ls = a

st = int(n/2)
for ind in range(st, 0, -1):
    tmp = list(range(2*ind-1, n, ind))
    s = ls[tmp].sum()%2
    if a[ind-1] == s:
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        
print(sum(ls))
ans = np.where(ls==1)[0] + 1
ans = list(ans.astype(str))
print(' '.join(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
li=list(map(int,input().split()))

ans=[]
for i in range(n-1,n//2-1,-1):
  if li[i]==1:
    ans.append(i+1)

for i in range(n//2,0,-1):
  count=0
  for j in ans:
    if j%i==0:
      count+=1
  count+=li[i-1]
  if count%2==1:
    ans.append(i)
ans.reverse()
print(len(ans))
L=[str(a) for a in ans]
L=" ".join(L)
if len(L)!=0:
  print(L)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    n = int(input())
    a = np.zeros([n], dtype=int)
    # box = np.array(range(1,n+1))
    a = list(map(int, input().split(" ")))
    b = np.zeros_like(a)

    for i in range(n//2, n):
        if a[i] == 1:
            b[i] = 1

    for i in range(1,n+1)[::-1]:
        if np.sum(b[i-1::i])%2 != a[i-1]:
            b[i-1] = 1

    ball = np.where(b==1)[0]
    print(len(ball))
    for i in ball:
        print(i+1, end=" ")
        
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
def cal(x):
    divisors = []
    for i in range(1, int(x**0.5)+1):
        if x % i == 0:
            divisors.append(i)
            if i != x // i:
                divisors.append(x//i)
    return divisors
num=[0 for _ in range(n+1)]
cnt=0
ans=[]
for k in range(n):
    if (num[n-k]+1)%2==a[-1-k]:
        ans.append(n-k)
        cnt+=1
        l=cal(n-k)
        for p in l:
            num[p]+=1
ans1=[]
for j in range(cnt):
    if j<cnt-1:
        ans1.append(str(ans[j]))
        ans1.append(" ")
    else:
        ans1.append(str(ans[j]))
print(cnt)
if len(ans1)>0:
    result=''.join(ans1)
    print(result)

Submission status: Time Limit Exceeded

Solution code:
def divisors(num, a):
    if num < 1:
        return
    elif num == 1:
        a[-1] = 1 - a[-1]
        return
    else:
        a[-1] = 1 - a[-1]
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                a[-i] = 1 - a[-i]
        a[-num] = 1 - a[-num]

        return

N = int(input())
a = list(reversed(list(map(int, input().split()))))

nums = []

while(True):
    if 1 not in a:
        break
    idx = a.index(1)
    divisors(N - idx, a)
    nums.append(N - idx)
    
print(len(nums))
if (len(nums) > 0): print(" ".join([str(n) for n in nums]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
li=list(map(int,input().split()))

ans=[]
for i in range(n//2,n):
  if li[i]==1:
    ans.append(i+1)
ans.reverse()
for i in range(n//2,0,-1):
  count=0
  for j in ans:
    if j%i==0:
      count+=1
  count+=li[i-1]
  if count%2==1:
    ans.append(i)
ans.reverse()
print(len(ans))
L=[str(a) for a in ans]
L=" ".join(L)
if len(L)!=0:
  print(L)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    n = int(input())
    a = np.zeros([n], dtype=int)
    box = np.array(range(1,n+1))
    a = list(map(int, input().split(" ")))
    b = np.zeros_like(a)

    for i in range(n//2, n):
        if a[i] == 1:
            b[i] = 1

    for i in box[:n//2][::-1]:
        if np.sum(b[i-1::i])%2 != a[i-1]:
            b[i-1] = 1

    ball = np.where(b==1)[0]
    print(len(ball))
    for i in ball:
        print(box[i], end=" ")
        

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = [0]*N

def bai_sum(A,n):
    global N
    sumup = 0
    for i in range(int(N/n)):
        sumup += A[n*(i+1)-1]
    return sumup % 2


for i in reversed(range(N)):
    if bai_sum(ans,(i+1)) != A[i]:
        ans[i] = 1
        
print(ans.count(1))

b=''
for i in range(N):
    if ans[i]==1 :
        hoge = i+1
        b = b+str(hoge)+' '

print(b)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))
b = []
c = np.zeros(N)
ans = 0
for i in reversed(range(1, N+1)):
    if (a[i-1] % 2 == 0 and c[i-1]%2 == 1) or (a[i-1] % 2 == 1 and c[i-1]%2 == 0):
        b.append(i)
        ans += 1
        for j in range(1,N+1):
            if i%j == 0:
                c[j-1] += 1

print(ans)
if ans != 0:
    print(*b)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    n = int(input())
    a = np.zeros([n], dtype=int)
    box = np.array(range(1,n+1))
    a = list(map(int, input().split(" ")))
    b = np.zeros_like(a)

    for i in range(n//2, n):
        if a[i] == 1:
            b[i] = 1

    for i in box[:n//2][::-1]:
        t = np.array(range(i, n+1, i))
        if np.sum(b[i-1::i])%2 != a[i-1]:
            b[i-1] = 1

    ball = np.where(b==1)[0]
    print(len(ball))
    for i in ball:
        print(box[i], end=" ")
        

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_l = list(map(int,input().split()))
ans_l = {}
for i,a in enumerate(a_l[::-1]):
    index = N-i
    curnum = 0
    for j in range(2,N//2):
        if(index*j<=N):
           curnum += ans_l[index*j]

    if(curnum%2!=a):
        ans_l[index] = 1
    else:
        ans_l[index] = 0

inlist = []
ans_len = 0
for key,num in ans_l.items():
    if(num==1):
        inlist.append(key)
        ans_len+=1

ans_str = " ".join(list(map(str,sorted(inlist))))
print(ans_len)
if(ans_str != ""):
    print(ans_str)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())

a = np.array(list(map(int, input().split())))

m = np.array([0] * (n+1))

def num_list(num):
    rep = n // num
    return [i*num for i in range(1, rep+1)]

def check(l):
    chk_list = num_list(l)
    if m[chk_list].sum() % 2 == 0:
        m[l] = a[l-1]
    else:
        m[l] = 1 - a[l-1]

for i in reversed(range(1, n+1)):
    check(i)

ans = np.where(m == 1)[0]

print(len(ans))

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arg = list(map(int, input().split()))
x = [0]*N

for i in range(N, N//2, -1):
  if arg[i-1] == 0:
    x[i-1] = 0
  else:
    x[i-1] = 1

for i in range(N//2, 0, -1):
  others = 0
  for j in range(N, i, -1):
    if j % i == 0:
      others += arg[j-1]
  if arg[i-1] % 2 != others % 2:
    x[i-1] = 1
  else:
    x[i-1] = 0
    
ans = []
if max(x) == 0:
  print(0)
else:
  for index in range(len(x)):
    if x[index] != 0:
      ans.append(index+1)
  print(len(ans))
  print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
m = 0
a = list(map(int,input().split()))
b = []
for i in range(n,0,-1):
  if n // i >= 2:
# i の倍数の箱のボールの数とa[i] でXORをとってあげる。
    if ((sum([a[j-1] for j in a if j%i == 0]))%2)%2:
      b.append(i)
  else:
    if a[i-1] == 1:
      b.append(i)
print(len(b))
#print(b)
if len(b) != 0:
  print(*b)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = input().split()
    b = []
    bb = []
    for _ in range(n):
        b.append(0)
    for i in range(n):
        ii = n - i
        sum = 0
        for j in range(ii,n):
            if (j + 1) % ii == 0:
                sum += b[j]
        if (sum % 2) != int(a[ii-1]):
            b[ii-1] = 1
    ss = 0
    for i in range(n):
        if b[i] == 1:
            ss += 1
            bb.append(i+1)
    print(ss)
    print(" ".join(map(str, bb)))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def calc(N, a):
    if (N == 1):
        if (a[0] == 0):
            return '0'
        else:
            return '1\n1'
    else:
        w = N // 2
        b = [0 for _ in range(N)]
        for i in range(w, N):
            b[i] = a[i]
        for i in range(N - 1, -1, -1):
            sum = 0
            start = [j for j in range(i + 1, i * 2 + 2) if j % (i + 1) == 0][0]
            for j in range(i + 1, N, i + 1):
                sum += b[j]
            b[i] = (a[i] + sum) % 2
        result = []
        for i in range(N):
            if (b[i] == 1):
                result += [i]
        s = str(len(result)) + '\n'
        for r in result:
            s += ' '.join(s)
        return s


N = int(input())
a = [int(s) for s in input().split(' ')]
print(calc(N, a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()] 

a = np.array(a)
ls = a

st = int(n/2)
for ind in range(st, 0, -1):
    tmp = list(range(2*ind-1, n, ind))
    s = ls[tmp].sum()%2
    if a[ind-1] == s:
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        
print(sum(ls))
ans = np.where(ls==1)[0] + 1
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(int, input().split()))
sol = arr[:]

for i in range(n):
    sol[n-i-1] = sum(sol[n-i-1::n-i]) % 2

a = sum(sol)
ls = ""
for i in range(n):
    if sol[i] == 1:
        ls = ls + " " + str(i+1)

print(a)
if ls != "":
    ls = ls[1:]
    print(ls)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque
import sys

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def d(n):
    divisors = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i * i != n:
                divisors.append(n // i)

    return divisors


def main():
    N = int(input())
    # A = [
    #     int(input())
    #     for _ in range(N)
    # ]
    A = [int(a) for a in input().split()]

    res_c = 0
    res1 = []
    bucket = [0] * (N + 1)

    i = N
    for Ai in reversed(A):
        i -= 1
        k = i + 1
        if k * 2 > N:
            if Ai == 1:
                res_c += 1
                res1.append(k)
                for j in range(2, int(k ** 0.5) + 1):
                    if k % j == 0:
                        bucket[j] += 1
                        if j * j != k:
                            bucket[k // j] += 1
            continue
        if k == 1:
            if res_c % 2 != Ai:
                res_c += 1
                res1.append(k)
            break

        if bucket[k] % 2 != Ai:
            res_c += 1
            res1.append(k)
            for j in range(2, int(k ** 0.5) + 1):
                if k % j == 0:
                    bucket[j] += 1
                    if j * j != k:
                        bucket[k // j] += 1
    print(res_c)
    print(*res1)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))
b = []
c = np.zeros(N)
ans = 0
for i in reversed(range(1, N+1)):
    j = 2
    count = 0
    while True:
        if i*j <= N:
            count += c[i*j-1]
            j += 1
        else:
            break
    if (a[i-1] % 2 == 0 and count%2 == 1) or (a[i-1] % 2 == 1 and count%2 == 0):
        b.append(i)
        ans += 1
        c[i-1] = 1

print(ans)
if ans != 0:
    print(*b)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

for i in range(2**N):
  temp = list(format(i,"0"+str(N)+'b'))
  temp1 = list(map(int, temp))
  for k in range(1,N+1):
    if sum(temp1[k-1::k])%2 == A[k-1]:
        pass
    else:
        break
  else:
    print(sum(temp1))
    anslist = []
    for i in range(N):
        if temp1[i] == 1:
          anslist.append(i+1)
    if anslist == []:
      exit()
    else:
      print(*anslist)
      exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))

b=[-1]*N
b[N-1]=a[N-1]
for i in range(N-1)[::-1]: #N=4なら 2,1,0
    sum_count = N // (i+1)
    if sum_count==1:
        b[i]=a[i]
    else:
        sum1=0
        for j in range(sum_count-1):
            sum1 = sum1 + b[(i+1)*(j+2)-1]
        sum1 = sum1 % 2
        b[i]=(a[i]+ sum1)%2

print(sum(b))
f=0
for i in range(N):
    if b[i]==1 and f==0:
        f=1
        out=str(i+1)
    elif b[i]==1:
        out = out + " " + str(i+1)
if f==1:
    print(out)

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    _ = int(input())
    A = list(map(int,input().split()))

    M = []
    lenA = len(A)
    for i in range(len(A))[::-1]:
        if i > lenA/2:
            if A[i] == 1:
                M.append(i+1)
        else:
            num = len([x for x in M if x%(i+1)==0]) % 2
            if A[i] != num:
                M.append(i+1)
    
    print(len(M))
    if len(M) > 0:
        print(*M)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split() ))
b=[0] * N
for i in range(N-1,-1,-1):
    if i > (N+1)/2:
        b[i]=a[i]
    else:
        tmp_list=[s for s,ind in zip(b,range(N)) if (ind+1)%(i+1)==0]
        b[i] = abs(a[i] - sum(tmp_list)%2 )
print(sum(b))
if sum(b) > 0:
    c = [1 for s,ind in zip(b,range(N)) if s==1]
    print(" ".join(map(str,c)) )

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

A=[int(i) for i in input().split()]
memo=[0 for i in range(n)]
ans=[]

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            memo[i-1]^=1
            if i != n // i:
                memo[n//i-1]^=1

    # divisors.sort()
    return divisors


for i in range(n-1,-1,-1):
    if not memo[i]==A[i]:
        ans.append(str(i+1))
        make_divisors(i+1)

print(len(ans))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_l = list(map(int,input().split()))
ans_l = {}
for i,a in enumerate(a_l[::-1]):
    index = N-i
    curnum = 0
    for j in range(2,N//2):
        if(index*j<=N):
           curnum += ans_l[index*j]
        else:
           continue
    if(curnum%2!=a):
        ans_l[index] = 1
    else:
        ans_l[index] = 0

inlist = []
ans_len = 0
for key,num in ans_l.items():
    if(num==1):
        inlist.append(key)
        ans_len+=1

ans_str = " ".join(list(map(str,sorted(inlist))))
print(ans_len)
if(ans_str != ""):
    print(ans_str)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
al=list(map(int,input().split()))
ac=0
ans=set()
tl=[0]*n
for i in range(n,0,-1):
    if tl[i-1]%2!=al[i-1]:
        ac+=1
        ans.add(i)
        for j in range(1,int(i**0.5)+1):
            if i%j==0:
                tl[j-1]+=1
                if j**2==i:
                    continue
                tl[i//j-1]+=1
print(ac)
if ac>0:
    print(' '.join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = []
b = [i+1 for i in range(n//2,n) if a[i] == 1]

for i in reversed(range((n//2))):
    if a[i] != len([x for x in b if x%(i+1) == 0])%2:
        b=[i+1] + b
        
print(len(b))
print(' '.join(map(str,b)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(int, input().split()))
sol = [arr[i] for i in range(n)]

for i in range(n):
    sol[n-i-1] = sum(sol[n-i-1::n-i])

result = [sol[i]%2 for i in range(n)]
a = sum(result)
ls = ""
for i in range(n):
    if result[i] == 1:
        ls = ls + " " + str(i+1)

print(a)
if ls != "":
    ls = ls[1:]
    print(ls)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

import numpy as np
import math
A = np.array(A)
b = np.zeros(N)
for i in reversed(range(1, N + 1)):
    a = A[i - 1]
    idxs = np.arange(1, math.floor(N / i) + 1) * i
    s = np.sum(b[idxs - 1])
    if (s % 2 == 0 and a == 1) or (s % 2 == 1 and a == 0):
        b[i - 1] = 1
    # print(i, idxs, s, b)


if len(b) == 0:
    print(0)
else:
    counter = 0
    res = ''
    for i in range(len(b)):
        if b[i] == 1:
            if res == '':
                res += str(i + 1)
            else:
                res += ' ' + str(i + 1)
            counter += 1
    print(counter)
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
num = list(map(int, input().split()))
frag = 0
ans = []
def unchi(i, n):
    if i == n:
        buri = []
    else:
        buri = [i]
        j = i
        while j < n:
            j += i
            if j <= n:
                buri.append(j)
    return buri 

for i in range(len(num)-1, -1, -1):
    cnt = 0
    if(num[i] == 1):
        for j in unchi(i+1, len(num)):
            if(j in ans):
                cnt += 1
        if(cnt % 2 == 0):
            ans.append(i+1)

    else:
        for j in unchi(i+1, len(num)):
            if(j in ans):
                cnt += 1
        if(cnt % 2 == 1):
            ans.append(i+1)
ans.reverse()
print(len(ans))
if len(ans) >= 1:
    for i in range(len(ans)):
        sys.stdout.write(str(ans[i]) + " ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy

N = int(input())  
a = np.array(input().split(), dtype=np.int32)
M = np.arange(N) + 1
    
for i in np.arange(N // 2)[::-1]:
    A = a[np.where(M % (i+1) == 0)]
    if np.sum(A) % 2  == 0:
        a[i] = 0
    else:
        a[i] = 1
        
ans = np.where(a == 1)[0] + 1

print(np.size(ans))

if np.size(ans) > 0:
    print(*ans.astype(np.int32))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

for i in range(2**N):
  im ="0" + str(N)
  temp = list(format(i, im+'b'))
  temp1 = list(map(int, temp))
  for k in range(1,N+1):
    if sum(temp1[k-1::k])%2 == A[k-1]:
        print()
        pass
    else:
        break
  else:
    print(sum(temp1))
    anslist = []
    for i in range(N):
        if temp1[i] == 1:
          anslist.append(i+1)
    if anslist == []:
      exit()
    else:
      print(*anslist)
      exit()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = []
b = 0
for i in range(n):
	j = n - 1 - i
	if b == 0:
		if a[j] == 1:
			ans.append(j+1)
			c = j + 1
			b = 1
	elif b == 1 and j + 1 > c / 2:
		if a[j] == 1:
			ans.append(j+1)
	else:
		rem = list(map(lambda x: x % (j + 1),ans))
		count = rem.count(0)
		count_01 = count % 2
		if a[j] == 0:
			if count_01 == 1:
				ans.append(j+1)
		elif a[j] == 1:
			if count_01 == 0:
				ans.append(j+1)
if not ans:
	print(0)
else:
	print(str(len(ans))+"\n" + " ".join(list(map(str,ans))))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))
b = []
c = np.zeros(N)
ans = 0
for i in reversed(range(1, N+1)):
    j = 2
    count = 0
    while True:
        if i*j <= N:
            count += c[i*j-1]
            j += 1
        else:
            break
    if (a[i-1] % 2 == 0 and count%2 == 1) or (a[i-1] % 2 == 1 and count%2 == 0):
        b.append(i)
        c[i-1] = 1
        ans += 1
    

b.reverse()
print(ans)
if ans != 0:
    print(*b)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque
import sys

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def d(n):
    divisors = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i * i != n:
                divisors.append(n // i)

    return divisors


def main():
    N = int(input())
    # A = [
    #     int(input())
    #     for _ in range(N)
    # ]
    A = [int(a) for a in input().split()]

    res_c = 0
    res1 = []
    bucket = [0] * (N + 1)

    i = N
    for Ai in reversed(A):
        i -= 1
        k = i + 1
        if k * 2 > N:
            if Ai == 1:
                res_c += 1
                res1.append(k)
                for di in d(k):
                    bucket[di] += 1
                # sq = int(k ** 0.5)
                # if sq * sq == k:
                #     bucket[sq] += 1
                # for j in range(2, sq):
                #     if k % j == 0:
                #         bucket[j] += 1
            continue
        if k == 1:
            if res_c % 2 != Ai:
                res_c += 1
                res1.append(k)
            break

        if bucket[k] % 2 != Ai:
            res_c += 1
            res1.append(k)
            for di in d(k):
                bucket[di] += 1
    print(res_c)
    print(*res1)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


N = int(input())
A = map(int, raw_input().split())
C = [0 for j in range(N)]
ANS = []

for j in range(N, 0, -1):
    m = A[j-1]
    am = C[j-1] % 2
    if m != am:
        ANS.append(j)
        div = make_divisors(j)
        for k in div:
            if k != j:
                C[k-1] += 1

print(len(ANS))
str_ANS = [str(j) for j in ANS]
print(" ".join(str_ANS))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split() ))
b=[0] * N
for i in range(N-1,-1,-1):
    if i > (N+1)/2:
        b[i]=a[i]
    else:
        tmp_list=[s for s,ind in zip(b,range(N)) if ind%(i+1)==0]
        b[i] = abs(a[i] - sum(tmp_list)%2 )
print(sum(b))
if sum(b) > 0:
    c = [1 for s,ind in zip(b,range(N)) if s==1]
    print(" ".join(map(str,c)) )

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
res = []
m = 0
for i in range(n//2,n):
    if a[i] == 1:
        res.append(i+1)
        m += 1
for i in range(n//2):
    k = n//2-i
    cnt = 0
    for j in res:
        if j % k == 0:
            cnt = (cnt+1)%2
    if cnt != a[k-1]:
        res.append(k)
        m += 1 
if m == 0:
    print(0)
else:
    print(m)
    for i in range(m):
        if i != 0:
            print(' ',end='')
        print(res[i],end='',)
    print()

Submission status: Time Limit Exceeded

Solution code:

import numpy as np
 
N = int(input())
t = np.array(range(1,N+1))
ans = np.zeros(N)
ans_final = []
amari = list(map(int,input().split()))
for i in range(N):
  sum = 0
  p = N-i
  for k in t[t%p == 0]:
    sum += ans[k-1]
  if (sum % 2) != amari[p-1]:
    ans[p-1] = 1
    ans_final.append(p)

print(len(ans_final))
print(*ans_final)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))

for i in range(2**n):
    b = [0]*n
    for j in range(n):
        if ((i >> j) & 1):
            b[j] = 1

    
    if any(sum(b[j::j+1])%2 != a[j] for j in range(n)):
        continue
    else:
        print(sum(b))
        for k in range(n):
            if b[k] == 1:
                print(k+1,end=" ")
        print()
        sys.exit()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A = [int(a) for a in input().split()]
#print(N,A)
B = [0]*N
for i in reversed(range(N)):
  C=[b for j,b in enumerate(B[(i+1):]) if (j+i+1)%(i+1) == 0]
  if sum(C)%2 == A[i]:
    B[i] = 0
  else:
    B[i] = 1
#print(B)
C = [str(i+1) for i,b in enumerate(B) if b == 1]
print(len(C))
print(" ".join(C))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()] 

a = np.array(a)
ls = a
def func(ind):
    tmp = list(range(2*ind-1, n, ind))
    s = ls[tmp].sum()
    return s%2

st = int(n/2)
for ind in range(st, 0, -1):
    if a[ind-1] == func(ind):
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        
print(sum(ls))
ans = np.where(ls==1)[0]+1
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import collections
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N = int(input())
a = list(int(i) for i in input().split())
ans_list = []
ans = 0
for i in range(N):
	if a[N-1-i] == 1:
		ans += 1
		ans_list.append(N-i)
		chk = make_divisors(N-i)
		for j in range(len(chk)):
			a[chk[j]-1] = (1+a[chk[j]-1])%2
print(ans)
if len(ans_list) != 0:
	print(*ans_list)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(bool, map(int, input().split())))
As.insert(0, False)
Ans = [False for _ in range(N + 1)]
Ans[N] = As[N]
for i in range(N - 1, 0, -1):
    p = i * 2
    s = False
    while p <= N:
        s ^= Ans[p]
        p += i
    Ans[i] = s ^ As[i]
M = sum(Ans)
print(M)
if M > 0:
    bs = ""
    for i in range(1, N + 1):
        if Ans[i]:
            bs += "%d " % i
    bs = bs.rstrip(" ")
    print(bs)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
al=list(map(int,input().split()))
ac=0
ans=set()
tl=[0]*n
for i in range(n,0,-1):
    if tl[i-1]%2!=al[i-1]:
        ac+=1
        ans.add(i)
        for j in range(1,i+1):
            if i%j==0:
                tl[j-1]+=1
print(ac)
if ac>0:
    print(' '.join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
n = N
for a in (reversed(A)):
    if n*2 > N:
        B[n-1] = a
        n -= 1
        continue
    total = 0
    for i in range(2,N+2):
        if n*i <= N:
            total += B[n*i-1]
        else:
            if a == total % 2:
                B[n-1] = 0
            else:
                B[n-1] = 1
    n -= 1

M = sum(B)
print(M)
C = [str(n+1) for n, v in enumerate(B) if v == 1]

print(' '.join(C))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = []
b = [i+1 for i in range(n//2,n) if a[i] == 1]
for i in reversed(range((n//2))):
    k = 0
    for j in range(len(b)):
        if b[j]%(i+1) == 0:
            k += 1
    if a[i] != k%2:
        b=[i+1] + b

print(len(b))
print(' '.join(map(str,b)))