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.

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
B=[0 for _ in range(N)]
def f(a,N):
    l=[]
    m=2*a
    while m<=N:
        l.append(m)
        m+=a
    return l

for a in range(1,N+1)[::-1]:
    idx=f(a,N)
    b_sum=0
    for i in idx:
        b_sum += B[i-1]
    B[a-1] = (A[a-1] - b_sum) % 2
ans=[i+1 for i in range(N) if B[i] != 0]
print(len(ans))
if len(ans)!=0:
    print(*ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
a = [int(i) for i in input().split()]

box = [0] * N

for i in range(N-1, -1, -1):
    
    count = 0
    n = i+1
    while n <= N:
        count += box[n-1]
        n += i + 1

    if count % 2 != a[i]:
        box[i] = 1

M = box.count(1)
print(M)

answer = [i+1 for i,x in enumerate(box) if x == 1]
if M > 0:
    print(' '.join(list(map(str,answer))))

Solution (Python):
def main():
    n = int(input())
    a_list = [-1]
    a_list += list(map(int, input().split()))

    bolls = [0] * (n + 1)
    m = 0
    for i in range(n, 0, -1):
        count = 0
        for j in range(2, n + 1):
            multiple = i * j
            if multiple > n:
                break
            else:
                count += bolls[multiple]
        temp = count % 2
        if a_list[i] != temp:
            bolls[i] = 1
            m += 1

    print(m)
    ans_list = []
    for i in range(1, n + 1):
        if bolls[i] >= 1:
            ans_list.append(i)
    print(' '.join(map(str, ans_list)))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = [0]
a += list(map(int, input().split()))
ans = [0]*(N+1)
for i in range(N, 0, -1):
    if i > N/2:
        ans[i] = a[i]
    elif i == 1:
        cnt = sum(ans)
        ans[i] = (a[i] + cnt) % 2
    else:
        num = N // i
        cnt = 0
        for j in range(2, num+1):
            cnt += ans[i * j]
        ans[i] = (a[i] + cnt) % 2

print(sum(ans))
s = ""
for i in range(N+1):
    if ans[i] == 1:
        s += str(i) + " "
print(s)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [-1] * (n + 1)
a.insert(0, 0)

for i in range(n, 0, -1):
    t_sum = 0
    j = 2 * i
    while j <= n:
        t_sum ^= b[j]
        j += i
    b[i] = t_sum ^ a[i]
print(sum(b[1:]))
for i in range(1, n + 1):
    if b[i] != 0:
        print(i, end = ' ')

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    l = [0 for _ in range(n)]
    for i in range(n-1, -1, -1):
        re_i = i + 1
        res = 0
        for j in range(0, n//re_i):
            re_j = j + 1
            res += l[(re_i * re_j) - 1]
        if res % 2 != a[i]:
            l[i] = 1
    ans = []
    for i in range(len(l)):
        if l[i] == 1:
            ans.append(i + 1)
    print(len(ans))
    if len(ans) == 0:
        sys.exit()
    else:
        print(" ".join(map(str, ans)))
            


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    l = [0 for _ in range(n)]
    for i in range(n-1, -1, -1):
        re_i = i + 1
        
        res = 0
        for j in range(0, n//re_i):
            re_j = j + 1
            
            
            res += l[(re_i * re_j) - 1]
        
        if res % 2 != a[i]:
            l[i] = 1
        
    ans = []
    for i in range(len(l)):
        if l[i] == 1:
            ans.append(i + 1)
    print(len(ans))
    if len(ans) == 0:
        sys.exit()
    else:
        print(" ".join(map(str, ans)))
            


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = [0] + list(map(int, input().split()))
b = []
for i in range(1, N+1)[::-1]:
    s = sum(a[j] for j in range(i*2, N+1, i))
    if s % 2 == 1:
        a[i] = 1 - a[i]
    if a[i]:
        b.append(i)
print(len(b))
if len(b) > 0:
    print(*b)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
b = [0] * N
for i in range(N, 0, -1):
    sum = 0
    for j in range(i*2, N+1, i):
        sum += b[j-1]
    if sum % 2 == 0:
        b[i-1] = a[i-1]
    else:
        b[i-1] = 1 - a[i-1]
count = b.count(1)
print(b.count(1))
if count > 0:
    ans = ''
    for i in range(1, N+1):
        if b[i-1] == 1:
            ans += str(i) + ' '
    print(ans[:-1])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

a = [0] + a
b = [0] * (n+1)

for i in range(n, 0, -1):
    sum = 0
    for j in range(i, n+1, i):
        sum ^= b[j]
    b[i] = sum^a[i]


ans = list()
for i in range(n+1):
    if b[i]: ans.append(i)

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

Solution (Python):
def divisors(n: int)->list:
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


def preparing_boxes(N: int, A: list)->list:
    B = []
    

    for i in range(N, 0, -1):
        
        a = A[i-1]
        if a == 0:
            continue
        B.append(i)
        

        for div in divisors(i):
            
            A[div-1] = 1 - A[div-1]

    

    return B


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = preparing_boxes(N, A)
    print(len(ans))
    print(' '.join(str(i) for i in ans))

Solution (Python):
n=int(input())
a=[0]+list(map(int,input().split()))
ball=[0]*(n+1)
for i in range(n,0,-1):
    c=1
    sum=0
    while c*i<=n:
        sum+=ball[c*i]
        c+=1
    ball[i]=(sum+a[i])%2
ans=[]
for i in range(1,n+1):
    if ball[i]!=0:
        ans.append(i)
print(len(ans))
"""if len(ans)==0:
    exit()"""
print(*ans)

Solution (Python):
n=int(input())
a=[0]+list(map(int,input().split()))
ball=[0]*(n+1)
for i in range(n,0,-1):
    c=1
    sum=0
    while c*i<=n:
        sum+=ball[c*i]
        c+=1
    ball[i]=(sum%2+a[i])%2
ans=[]
for i in range(1,n+1):
    if ball[i]!=0:
        ans.append(i)
print(len(ans))
"""if len(ans)==0:
    exit()"""
print(*ans)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
li = [0] + list(map(int,stdin.readline().rstrip().split()))
lin = [0]*(n+1)
point = 0
lis = []

for i in range(n,0,-1):
    su = sum(lin[i::i])%2
    if li[i] != su:
        lin[i] = 1
        point += 1
        lis.append(i)
    
print(point)
lis.sort()

for i in lis:
    print(i)

Solution (Python):
import sys
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]

for i in range(n) :
  j = n - (i+1)
  if j == 0 :
    if a[0] == 1 and sum(b)%2 == 0 :
      b[0] = 1
    if a[0] == 0 and sum(b)%2 == 1 :
      b[0] = 1
  elif n//(j+1) == 1 :
    if a[j] == 1 :
      b[j] = 1
  else :
    k = 2
    b_sum = 0
    while n >= k*(j+1) :
      b_sum += b[k*(j+1)-1]
      k += 1
    if a[j] == 1 and b_sum%2 == 0 :
      b[j] = 1
    if a[j] == 0 and b_sum%2 == 1 :
      b[j] = 1
      
print(sum(b))

ans = []
if sum(b) != 0 :
  for i in range(n) :
    if b[i] == 1 :
      ans.append(str(i+1))
  print(*ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))

ans=set()
for i in range(n-1,-1,-1):
  for j in range(i+1,n+1,i+1):
    if j in ans:
      A[i]+=1
  if A[i]%2:
    ans.add(i+1)
print(len(ans))
print(*ans)

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

M = 0
boxes = [0]*N
for i in reversed(range(N)):
    num_balls = 0
    for k in range(i, N, i+1):
        num_balls += boxes[k]
    if num_balls%2 != a[i]:
        boxes[i] = 1
        M += 1

print(M)
for i in range(N):
    if boxes[i]==1:
        print(i+1)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ans = []
def divisor(n):
  ret = [0]
  for i in range(2,int(n**(1/2))+1):
    if n%i==0:
      ret.append(i-1)
      
      comp=n//i
      if i!=comp:
        ret.append(comp-1)
      
  return ret

for i in reversed(range(N)):
  if a[i]:
    ans.append(i+1)
    lis = divisor(i+1)
    for j in lis:
      a[j]^=1
      
l = len(ans)
if l>0:
  print(l)
  print(*ans)
else:
  print(l)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
M = 0
B = [0]*N
for i in reversed(range(N)):
    tmp = 0
    for k in range(i, N, i+1):
        tmp += B[k]
    if tmp % 2 != A[i]:
        B[i] = 1
        M += 1
print(M)
for i in range(N):
    if B[i] == 1:
        print(i+1)

Solution (Python):

import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())
A = [0] + list(map(int, input().split()))

B = [0]*(N+1)
for i in reversed(range(1,N+1)):
    k = i
    cnt = 0
    while k <= N:
        cnt += B[k]
        k += i
    
    if cnt%2 != A[i]:
        B[i] = 1

print(sum(B))
for i in range(1,N+1):
    if B[i] == 1:
        print(i)

Solution (Python):
N = int(input())
nums = [0 for _ in range(N+1)]
A = list(map(int, input().split(' ')))
A.insert(0, 0)

for i in range(N, 0, -1):
    s = sum([nums[j] for j in range(i, N+1, i)])
    if s % 2 != A[i]:
        nums[i] = 1

print(sum(nums))
print(' '.join([str(i) for i, num in enumerate(nums) if num == 1]))

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
a = [-1] + a
count = 0

for i in range(N//2, 0, -1):
    d = N//i
    for j in range(2,d+1):
        count += a[i*j]
    if a[i] % 2 != count % 2:
        a[i] = 1
    else:
        a[i] = 0
    count = 0
print(sum(a)+1)
for i in range(1,N+1):
    if a[i] == 1:
        print(i, end=' ')

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(N)]
M=0
C_list=[]

for n in range(N,0,-1):
    K=N//(n)
    for m in range(K):
        if m==0:
            B[n-1]+=A[n-1]
        else:
            B[n-1]+=B[n-1+n*m]
    B[n-1]%=2
    if B[n-1]:
        C_list.append(n)
    M+=B[n-1]

S=" ".join(list(map(str,reversed(C_list))))
print(M)
print(S)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
 
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
 
 
tmp = [0]*(N+1)
b = [0]*N
ball_num = 0
ball_box = []
for i in reversed(range(N)):
    if a[i] == 0:
        if (tmp[i+1]%2) == 0:
            continue
        else:
            ball_box.append(i+1)
            ball_num += 1
            val = make_divisors(i+1)
            for elms in val:
                tmp[elms] += 1
    elif a[i] == 1:
        if (tmp[i+1]%2) == 0:
            ball_box.append(i+1)
            ball_num += 1
            val = make_divisors(i+1)
            for elms in val:
                tmp[elms] += 1
        else:
            continue
 
print(ball_num)
if ball_num != 0:
    print(*ball_box)

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
A=[0]*n
for i in range(n-1,-1,-1):
  if i>=n//2:
    A[i]=b[i]
  else:
    a=0
    for j in range(2*i+1,n,i+1):
      a=(a+A[j])%2
    if b[i]==a:
      A[i]=0
    else:
      A[i]=1
print(sum(A))
for i in range(n):
  if A[i]==1:
    print(i+1,end=" ")

Solution (Python):
import sys

input = sys.stdin.readline

def main(): 
    N = int(input())
    A = [0] + list(map(int, input().split()))
    
    ans = [0] * (N+1)
    c = 0
    for i in range(N, 0, -1):
        t = sum(ans[i::i])
            
        if A[i] != (t%2): 
            ans[i] = 1
            c += 1
            
    print(c)
    for idx, n in enumerate(ans): 
        if n: print(idx, '', end='')

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
B,C=[0 for i in range(n+1)],[]
cnt=0
for i in range(1,n+1)[::-1]:
    sum_list=sum([B[j] for j in range(i,n+1,i)])
    if sum_list%2!=A[i-1]:
        B[i]=1
        cnt +=1
        C.append(i)
print(cnt)
print(*[i for i in C[::-1]])

Solution (Python):
n = int(input())
a = [num for num in map(int, input().split(' '))]



ans = [0] * (n+1)

for i in range(n):
  
  target_i = n - i
  a_targt = a[n-i-1]
  
  
  baisu = 2
  ball_count = 0
  while True:
    baisu_i = target_i * baisu
    if baisu_i > n:
      break
    if ans[baisu_i] == 1:
      ball_count += 1
    baisu += 1
  
  if ball_count % 2 != a_targt:
    ans[target_i] = 1

ans_array = []

for i in range(1, n+1):
  if ans[i] == 1:
    ans_array.append(i)
print(len(ans_array))
if len(ans_array) > 0:
  print(' '.join(map(str, ans_array)))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
B,C=[0 for i in range(n+1)],[]
cnt=0
for i in range(1,n+1)[::-1]:
    sum_B=sum(B[j] for j in range(i,n+1,i))
    if sum_B%2!=A[i-1]:
        B[i]=1
        cnt +=1
        C.append(i)
print(cnt)
print(*[i for i in C[::-1]])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
c = [0]
d = c + a
s = [0 for i in range(n + 1)]

for i in range(n, 0, -1):
    w = 0
    for j in range(2 * i, n + 1, i):
        w ^= s[j]
    s[i] = w ^ d[i]

print(sum(s))
for i in range(1, n + 1):
    if s[i]:
        print(i,end=' ')

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(n+1)]
C=[]
cnt=0
for i in range(1,n+1)[::-1]:
    sum_B=sum(B[j] for j in range(i,n+1,i))
    if sum_B%2!=A[i-1]:
        B[i]=1
        C.append(i)
        cnt +=1
print(cnt)
print(*[i for i in C[::-1]])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
b = [0 for _ in range(N)]
for i in range(N, 0, -1):
    b[i-1] = 0 if sum(b[i-1::i]) % 2 == A[i-1] else 1
ans = [str(i+1) for i, x in enumerate(b) if x == 1]
print(len(ans))
if ans:
    print(' '.join(ans))

Solution (Python):

import sys











def main():
    n, *a = [int(x) for x in sys.stdin.read().split()]
    a = [None] + a

    in_or_not = [0 for _ in range(n+1)]
    for i in range(n, 0, -1):
        count = sum(in_or_not[2*i:n+1:i])  
        in_or_not[i] = a[i] ^ count % 2
    
    print(in_or_not.count(1))
    for i in range(1, n+1):
        if in_or_not[i] == 1:
            print(i, end=' ')


if __name__ == "__main__":
    main()

Solution (Python):

import sys











def main():
    n, *a = [int(x) for x in sys.stdin.read().split()]
    a = [None] + a

    in_or_not = [0 for _ in range(n+1)]
    for i in range(n, 0, -1):
        count = 0
        for j in range(2 * i, n+1, i):
            count += in_or_not[j]
        
        in_or_not[i] = a[i] ^ count % 2
    

    print(in_or_not.count(1))
    for i in range(1, n+1):
        if in_or_not[i] == 1:
            print(i, end=' ')




if __name__ == "__main__":
    main()

Solution (Python):

import sys











def main():
    n, *a = [int(x) for x in sys.stdin.read().split()]
    a = [None] + a

    in_or_not = [0 for _ in range(n+1)]
    for i in range(n, 0, -1):
        count = 0
        for j in range(2 * i, n+1, i):
            count += in_or_not[j]
        if a[i] == 1:
            if count % 2 == 0:
                in_or_not[i] = 1
        else:
            if count % 2 == 1:
                in_or_not[i] = 1
    

    print(in_or_not.count(1))
    for i in range(1, n+1):
        if in_or_not[i] == 1:
            print(i, end=' ')




if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = [0] + list(map(int, input().split()))
ans = [0] * (n+1)
for i in range(n,0,-1):
  SUM = 0
  for j in range(i,n+1,i):
    SUM += ans[j]
  ans[i] = (SUM + a[i]) % 2
m = 0
b = []
for key,i in enumerate(ans):
  if i:
    m += 1
    b.append(key)
print(m)
print(*b)

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines



























def main():
	n=int(input())
	A=list(map(int,input().split()))
	ans=[0]*(n+1)
	
	for i in range(n,0,-1):
		ans[i]=(sum(ans[::i])%2) ^ A[i-1]
	
	print(sum(ans))
	print(*[i for i,x in enumerate(ans) if x==1])
	
	
if __name__ == '__main__':
	main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines



























def main():
	n=int(input())
	A=list(map(int,input().split()))
	ans=[0]*(n+1)
	
	for i in range(n,0,-1):
		ans[i]=(sum(ans[::i])%2) ^ A[i-1]
	
	print(sum(ans))
	print(*[i for i,x in enumerate(ans) if x==1])
	
	
if __name__ == '__main__':
	main()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n-1,0,-1):
    a[i] = sum(a[i::i+1]) % 2
a[0] = sum(a) % 2
ans = []
for i in range(n):
    if a[i] == 1:
        ans.append(i+1)
print(len(ans))
if len(ans) != 0:
    print(' '.join(map(str,ans)))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a = [0] + a
for i in range(n,0,-1):
    a[i] = sum(a[i::i]) % 2
ans = []
for i in range(len(a)):
    if a[i] == 1:
        ans.append(i)
print(len(ans))
if len(ans) != 0:
    print(' '.join(map(str,ans)))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[0 for i in range(n)]
res=0
for i in range(n-1,-1,-1):
    cnt=0
    for j in range(i,n,i+1): 
        cnt+=b[j]
    if cnt%2!=a[i]:
        b[i]+=1
        res+=1

print(res)
if res==0:
    exit()
for i in range(n):
    if b[i]==1:
        print(i+1)

Solution (Python):

N = int(input())
A = [0]+list(map(int,input().split()))
B = []
T = [0]*(N+1)

for i in range(N,0,-1):
    total = 0
    v = i
    while v <= N:
        total += T[v]
        v += i
    if total%2 != A[i]:
        T[i]=1
        B.append(i)

B.sort()
if len(B)>0:
    print(len(B))
    print(*B)
else:
    print(0)

Solution (Python):
import math

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(map(int, input().split()))
ans = [0 for i in range(n)]
ball = []

for ii in range(n):
    
    i = n-ii
    if(a[i-1]!=ans[i-1]):
        d = make_divisors(i)
        ball.append(i)
        for k in d:
            ans[k-1] = 1-ans[k-1]
print(len(ball))
print(' '.join(map(str,ball)))

Solution (Python):
import math

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(map(int, input().split()))
ans = [0 for i in range(n)]
ball = []

for ii in range(n):
    
    i = n-ii
    if(a[i-1]!=ans[i-1]):
        d = make_divisors(i)
        ball.append(i)
        for k in d:
            ans[k-1] = 1-ans[k-1]
print(len(ball))
print(' '.join(map(str,ball)))

Solution (Python):

def make_divisors(value):
    divisors = []
    
    for i in range(1, int(value ** 0.5) + 1):
        if value % i == 0:
            divisors.append(i)              
            if i != value // i:             
                divisors.append(value//i)   
    
    
    return divisors
 
N = int(input())
a = list(map(int, input().split()))
memo = [0] * N
anser = []
for i in range(N - 1, -1, -1):
    if (a[i] == 1 and memo[i] == 0) or (a[i] == 0 and memo[i] == 1):
        anser.append(i + 1)
        
        divisors = make_divisors(i + 1)
        for j in divisors:
            memo[j - 1] = (memo[j - 1] + 1) % 2
 
print(len(anser))
if len(anser) >=  1:
    print(" ".join(map(str, anser)))

Solution (Python):
import os

input = os.sys.stdin.readline

N = int(input())

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

ans = False
b = [0]*N

for i in range(N, 0 ,-1):
    b_sum = 0
    for j in range(i, N+1, i):
        b_sum += b[j-1]
    if b_sum % 2 != a[i-1]: b[i-1] = 1
if b==[0]*N:print(0)      
else:
    print(sum(b))
    print(*[k+1 for k, l in enumerate(b) if l==1])

Solution (Python):
N = int(input())

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

ans = False
b = [0]*N


for i in range(N, 0 ,-1):
    b_sum = 0
    for j in range(i, N+1, i):
        b_sum += b[j-1]
    if b_sum % 2 != a[i-1]: b[i-1] = 1
if b==[0]*N:print(0)      
else:
    print(sum(b))
    print(*[k+1 for k, l in enumerate(b) if l==1])

Solution (Python):
N = int(input())

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

ans = False
b = [0]*N


for i in range(N, 0 ,-1):
    b_sum = 0
    for j in range(i, N+1, i):
        b_sum += b[j-1]
    if b_sum % 2 != a[i-1]: b[i-1] = 1
if b==[0]*N:print(0)      
else:
    print(sum(b))
    print(*[k+1 for k, l in enumerate(b) if l==1])

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    a = list(map(int, input().strip().split()))
    ans = [0] * N

    for i, a_r in enumerate(a[::-1]):
        j = N - i - 1
        count = 0
        now = j+1
        while now <= N:
            count += ans[now-1]
            now += j+1

        if a_r == 0:
            if count % 2 == 1:
                ans[j] = 1
        else:
            if count % 2 == 0:
                ans[j] = 1

    output = ""
    count = 0
    for i, b in enumerate(ans):
        if b == 1:
            output += str(i+1) + " "
            count += 1
    print(count)
    if count != 0:
        print(output[:-1])


if __name__ == "__main__":
    main()

Solution (Python):
def solve():
    N, *a_l = map(int, open(0).read().split())
    a_l = [0] + a_l

    for i in range(N//2, 0, -1):
        a_l[i] = sum(a_l[i::i]) % 2

    b_l = [i for i, x in enumerate(a_l) if x]

    print(len(b_l))
    if len(b_l) != 0:
        print(' '.join(map(str, b_l)))


if __name__ == '__main__':
    solve()

Solution (Python):
class Solver():
  def __init__(self):
    self._N = int(input())
    self._data = list(map(int, input().split()))
    self._ans  = [0 for i in range(self._N)]
  
  def print_member(self):
    print("N = {}".format(self._N))
    for i in self._data:
      print(i, end=" ")
      
  
  def solve(self):
    flag = True
    for i in reversed(range(1,self._N+1)):
      i_mul   = i
      sum_mul = 0
      while(i_mul<self._N+1):
        sum_mul += self._ans[i_mul-1]
        i_mul   += i
      if(sum_mul%2 != self._data[i-1]):
        self._ans[i-1] += 1
        self._ans[i-1] %= 2
             
    if(flag):
      print(sum(self._ans))
      for i in range(self._N):
        if(self._ans[i]):
          print(i+1, end=" ")
          
if __name__ == '__main__':
  solver = Solver()
  solver.solve()

Solution (Python):
n = int(input())
a = list(map(int, input().split( )))
ans = [0]*n
for i in range(n,0,-1):
    tmp = a[i-1]
    for j in range(n//i,1,-1):
        tmp+=ans[i*j-1]
    ans[i-1] = tmp%2


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

Solution (Python):
def main():
    n=int(input())
    a = list(map(int,input().split()))
    if a==[0 for _ in range(n)]:
        print(0)
        return
    box=[0 for _ in range(n)]
    for i in range(n,0,-1):
        if n//i==1:
            box[i-1]=a[i-1]
        else:
            c=0
            for j in range((n//i)-1):
                c+=box[(j+2)*i-1]
            box[i-1]=(a[i-1]+c)%2
    print(sum(box))
    ans=[]
    for i in range(n):
        if box[i]==1:
            ans.append(str(i+1))
    print(' '.join(ans))

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
Bn =  list(map(int,input().split(' ')))

output_list = []

for i in reversed(range(N)):
    current_sum = 0
    target_num = i+1
    target_num_idx = 0
    for j in range((N)//(target_num)):
        target_num_idx = target_num_idx + target_num
        current_sum += Bn[target_num_idx -1]
    if current_sum % 2 != Bn[i]:
        if Bn[i] == 1:
            Bn[i] = 0
        else:
            Bn[i] = 1
    if Bn[i] == 1:
        output_list.append(target_num)
print(len(output_list))
output_list.reverse()
print(' '.join(map(str,output_list)))

Solution (Python):
import unittest


class TestD(unittest.TestCase):
    def test_1(self):
        a = [1, 0, 0]
        b = think(a)
        self.assertEqual(is_valid(a, b), True)

    def test_2(self):
        a = [0, 0, 0, 0, 0]
        b = think(a)
        self.assertEqual(is_valid(a, b), True)

    def test_3(self):
        a = [1, 1, 1, 1, 1, 1, 1]
        b = think(a)
        self.assertEqual(is_valid(a, b), True)

    def test_4(self):
        a = [1, 1, 1, 0, 1, 1, 0, 0]
        b = think(a)
        self.assertEqual(is_valid(a, b), True)


def solve():
    a = read()
    b = think(a)
    write(b)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    b = [0 for x in range(len(a))]
    for i in range(len(a), 0, -1):
        
        count = 0
        for j in range(i, len(a) + 1, i):
            
            count += b[j - 1]
        
        if a[i - 1] % 2 == count % 2:
            b[i - 1] = 0
        else:
            b[i - 1] = 1
    result = []
    for i in range(len(b)):
        if b[i] == 1:
            result.append(i + 1)
    return result


def write(b):
    print(len(b))
    print(' '.join(list(map(str, b))))


def is_valid(a, b):
    buf = [0 for x in range(len(a))]
    for i in b:
        buf[i - 1] = 1
    for i in range(len(a)):
        mod = i + 1
        count = 0
        for j in range(len(a)):
            to_be_divided = j + 1
            if to_be_divided % mod == 0:
                if buf[j]:
                    count += 1
        if count % 2 == a[i]:
            continue
        return False
    return True


if __name__ == '__main__':
    
    solve()

Solution (Python):



n = int(input())
al = list(map(int,input().split()))

ans_l = [0 for i in range(n)]
for i in reversed(range(n+1)):
    if i == 0:
        break
    now = 0
    for j in range(2,n+1):
        if j * i <= n:
            now += ans_l[j*i-1]
        else:
            break
    if now%2 == al[i-1]:
        ans_l[i-1] = 0
    else:
        ans_l[i-1] = 1
        
print(sum(ans_l))
for idx,i in enumerate(ans_l):
    if i == 1:
        print(idx+1)

Solution (Python):
n = int(input())
ai = list(map(int, input().split()))


dai={}
dbi={}
for i in range(1, n+1):
    dai.setdefault(i, ai[i-1])
    dbi.setdefault(i, 0)




anssum=0
ans=[]
for i in range(1, n+1)[::-1]:
    
    tmp=0
    for j in range(2, n+1):
        check=i*j
        if check <= n:
            tmp = tmp + dbi[check]
        else:
            break
    tmp = tmp%2
    
    if tmp != dai[i]:
        dbi[i]=1
        anssum=anssum+1
        ans.append(i)


print(anssum)
if anssum != 0:
    print(" ".join(map(str, reversed(ans))))

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

t = [0] * N
for i in range(N - 1, -1, -1):
    t[i] = (sum(t[2 * (i + 1) - 1::i + 1]) % 2) ^ a[i]

print(sum(t))
print(*[i + 1 for i in range(N) if t[i] == 1])

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

t = [0] * (N + 1)
for i in range(N, 0, -1):
    t[i] = (sum(t[2 * i::i]) % 2) ^ a[i - 1]

print(sum(t))
print(*[i for i in range(1, N + 1) if t[i] == 1])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=[]
def divis(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            a[i-1]^=1
            if i != n // i :
                ij=n//i
                a[ij-1]^=1
for i in reversed(range(n)):
    if a[i]==1:
        cnt.append(i+1)
        divis(i+1)
if len(cnt)>0:
    print(len(cnt))
    print(*cnt)
else:
    print(0)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=['$']+list(map(int,input().split())) 
    ans=[0]*(n+1)
    for i in range(n,0,-1): 
        parity=A[i]
        for j in range(2,n//i+1): 
            parity+=ans[i*j]
        if(parity%2): ans[i]=1
    s=sum(1 for i in range(1,n+1) if ans[i])
    print(s)
    if(s):
        print(*(i for i in range(1,n+1) if ans[i]))
resolve()

Solution (Python):
n=int(input())
a=[0]+list(map(int,input().split()))
b=[0]*(n+1)
for i in reversed(range(1,n+1)):
    if sum(b[i::i])%2!=a[i]:
        b[i]=1
print(sum(b))
for i,j in enumerate(b):
    if j==1:
        print(i,end=' ')

Solution (Python):
n = int(input())
a = input()
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = (ord(a[2 * i - 2]) + sum(r[i * 2::i])) % 2
print(r.count(1))
print(*(i for i, x in enumerate(r) if x))

Solution (Python):

import sys

MOD = 2  


def solve(N: int, a: "List[int]"):
    answer = [0]*(N+1)
    for i in range(N,0,-1):
        for j in range(2*i,N+1,i):
            answer[i] += answer[j]
        if a[i-1]==1:
            answer[i]= 1 if answer[i]%2==0 else 0
        else:
            answer[i]= 0 if answer[i]%2==0 else 1
    print(sum(answer))

    answer2 = []
    for index,ans in enumerate(answer):
        if ans == 1:
            answer2.append(index)

    print(*answer2)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [-1]+list( map(int, input().split()) )
b = [0]*(n+1)
res = 0
ary = []

for i in range(n, 0, -1):
    tmp = 0
    for j in range( 2*i, n+1, i ):
        tmp += b[j]
    if tmp%2 != a[i]:
        res += 1
        b[i] = 1
for i in range(1, n+1):
    if b[i] == 1:
        ary.append(i)
print(res)
if res != 0:
    print(*ary)