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 = list(map(int,input().split()))
ans = 0
B = [0]*N
for i in range(N-1,-1,-1):
    k = sum(B[i::i+1])
    if k%2!=A[i]:
        B[i]=1
        ans+=1
print(ans)
print(*[i+1 for i in range(N) if B[i]==1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
l = [0]*n
l2 = []
for i in range(n):
    if (n-i)*2 > n:
        l[n-i-1] = a[n-i-1]
        if a[n-i-1] == 1:
            l2.append(n-i)
    else:
        count = n//(n-i)
        count1 = 0
        for x in range(2,count+1):
            count1 = l[((n-i)*x)-1] + count1
        if (count1)%2 == a[n-i-1]:
            l[n-i-1] = 0
        else:
            l[n-i-1] = 1
            l2.append(n-i)
print(len(l2))
if len(l2) > 0:
    for i in l2:
        print(i, end=" ")

Solution (Python):






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

ans = [0]*n
for i in range(n)[::-1]:
    for j in range(0,n+1,i+1)[::-1]:
        if j == 0:
            continue
        if j-1 == i:
            if a[i] == ans[i]:
                ans[i] = 0
            else:
                ans[i] = 1
        else:
            ans[i] = (ans[i] + ans[j-1]) % 2
cnt = sum(ans)
b = []
for i in range(n):
    if ans[i] == 1:
        b.append(i+1)
print(cnt)
if cnt:
    print(*b)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[]
bb=b.append
for i in range(n,0,-1):
    if i>n//2:
        bb(a[i-1])
    else:
        cnt=0
        j=3
        while(True):
            if i*j>n:
                break
            if b[n-i*j]==1:
                cnt+=1
            j+=2
        bb((cnt+a[i-1]+a[i*2-1])%2)
b=list(reversed(b))
print(sum(b))
if sum(b)>0:
    c=[]
    cc=c.append
    for i,j in enumerate(b):
        if j==1:
            cc(str(i+1))
    print(" ".join(c))

Solution (Python):


import math
import sys
import itertools
import numpy as np


n =int(input())


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

b = [0]*n

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

for i in range(n//2,-1,-1):
    p=a[i]
    for j in range(2*i+1,n,i+1):
        p = (p ^ b[j])
    b[i]=p

ball = 0
for i in range(n):
    ball += b[i]
print(ball)
for i in range(n):
    if b[i]==1:
        print(i+1,end=' ')
print("")

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

b = [0 for i in range(n)]
ans = 0
for i in range(n-1, -1, -1):
    if a[i] == 1:
        cnt = 0
        for j in range(n//(i+1), 1, -1):
            cnt += b[j*(i+1)-1]
        if cnt%2 == 0:
            b[i] = 1
            ans += 1
    else:
        cnt = 0
        for j in range(n//(i+1), 1, -1):
            cnt += b[j*(i+1)-1]
        if cnt%2 == 1:
            b[i] = 1
            ans += 1
print(ans)
for i in range(n):
    if b[i] == 1:
        print(i+1)

Solution (Python):


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

c = [0] * (N+1)
for i in range(N, 0, -1):
    check_sum = sum(c[::i]) % 2
    if check_sum != a[i-1]:
        c[i] = 1

m = sum(c)
b = [i for i, x in enumerate(c) if x == 1]

print(m)
print(" ".join(map(str, b)))

Solution (Python):
def getlist():
	return list(map(int, input().split()))

N = int(input())
a = getlist()
L = [0] * N
ans = []

c = 0
for i in range(N):
	x = int(N // (N - i))
	val = 0
	for j in range(1, x):
		if L[(N - i) * (j + 1) - 1] == 1:
			val += 1
	if val % 2 != a[N - 1 - i]:
		L[N - 1 - i] = 1
		ans.append(N - i)
		c += 1

print(c)
ans = list(map(str, ans))
print(" ".join(ans))

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
a = LI()

b = [0 for i in range(N)]
cnt = 0
for i in reversed(range(N)):
    part_sum = 0
    step_cnt = N // (i+1)
    for step in range(2,step_cnt+1):
        
        part_sum += b[step * (i+1)-1]
    
    b[i] = (part_sum + a[i]) % 2


poss = []
for i in range(N):
    if b[i] == 1:
        cnt += 1
        poss.append(i+1)

print(cnt)
for pos in poss:
    print(pos)

Solution (Python):
import sys

fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
a_list = [int(elem) for elem in fin().split()]


inv_a_list = a_list[::-1]

ball_list = [0 for _ in range(N)]
ball_idx = []
for i, each_a in enumerate(inv_a_list):
    current_idx = N-i
    sup_sum = sum([ball_list[j * current_idx-1] for j in range(2, int(N / current_idx)+1)])
    if (each_a + sup_sum) % 2 == 0:
        continue
    else:
        ball_list[current_idx-1] = 1
        ball_idx.append(str(current_idx))

print(sum(ball_list))

if len(ball_idx) > 0:
    print(' '.join(ball_idx))

Solution (Python):
def main():
  n = int(input())
  a = list(map(int, input().split()))
  v = [0] * n

  for i in range(n - 1, -1, -1):
    x = sum(v[i::i + 1]) % 2

    if x != a[i]:
      v[i] = 1

  idx = [str(i + 1) for i, x in enumerate(v) if x == 1]

  print(len(idx))

  if len(idx) != 0:
    print(' '.join(idx))


if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
def f():
    b = [0] * n
    for i in range(n-1, -1, -1):
        b[i] = a[i] ^ (sum(b[i::i+1]) & 1)
    return b
res = [i+1 for i, x in enumerate(f()) if x > 0]
print(len(res))
print(' '.join(map(str, res)))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
Ans = []
temp = [0]*(N+1)

def factor(num):
    sqrt = num**0.5
    for i in range(1,int(num**0.5)+1):
        if i == sqrt:
            temp[i] += 1
        elif num%i == 0:
            temp[i] += 1
            temp[num//i] += 1
    return


for a,i in zip(A[::-1],range(N-1,-1,-1)):
    if a == 1 and temp[i+1] == 0:
        factor(i+1)
        Ans.append(i+1)
    elif temp[i+1]%2 != a:
        factor(i+1)
        Ans.append(i+1)
if len(Ans) == 0:
    print(0)
else:
    print(len(Ans))
    print(*Ans,sep = " ")

Solution (Python):
import sys

input = sys.stdin.readline

N = int(input().strip())
As = list(map(int, input().strip().split(' ')))
Bs = [0] * N

for i in range(N - 1, -1, -1):
    if i >= N // 2:
        Bs[i] = As[i]
    else:
        Bs[i] = abs(As[i] - (sum(Bs[2 * i + 1::i + 1]) % 2))

M = sum(Bs)
print(M)
if M != 0:
    print(" ".join(str(i+1) for i, b in enumerate(Bs) if b == 1))

Solution (Python):
import math

n=int(input())
alist=list(map(int, input().split())) 
blist=[]
for i in range(n):
    blist.append([])

for i in range(n):
    ima=n-i-1
    kosu=math.floor(n/(ima+1))
    nanko=0
    
    for j in range(kosu-1):
        
        nima=(ima+1)*(kosu-j)-1
        
        if blist[nima][0]==1:
            nanko+=1
    nanko=nanko%2
    if alist[ima]==nanko:
        blist[ima]=[0]
    else:
        blist[ima]=[1]


kotaelist=[]
for bl in range(n):
    if blist[bl]==[1]:
        kotaelist.append(bl+1)

print(len(kotaelist))
for s in kotaelist:
    print(s, end =" ")

Solution (Python):
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = li()
    box_list = [0] * n
    div = 1
    while n // (div + 1) - 1 >= 0:
        for i in range(n // div - 1, n // (div + 1) - 1, -1):
            value = a_list[i]
            index = (i + 1) * 2 - 1
            while index < n:
                value = value ^ box_list[index]
                index = index + (i + 1)
            box_list[i] = value
            
        div = div + 1
    box_sum = sum(box_list)
    box_list[0] = (box_sum % 2) ^ a_list[0]
    print(box_sum + box_list[0])
    for index, box in enumerate(box_list):
        if box == 1:
            print(index + 1, end=" ")

Solution (Python):
N = int(input())
A = [None] + list(map(int, input().split()))

B = [None] * (N+1)

C = []

for i in range(N+1 -1, 1 -1, -1):
  ans = A[i]
  j = i*2
  while j <= N:
    if B[j]:
      ans ^= 1
    j += i
  B[i] = ans
  if ans:
    C.append(i)

print(sum(B[1:]))
print(*C)

Solution (Python):




def make_divisors(n):
    divisors = []
    if n <= 0:
        return []
    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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = []
    balls_in_multiple = [0 for _ in range(N + 1)]
    count = 0
    for i in range(N, 0, -1):
        if balls_in_multiple[i] % 2 != A[i - 1]:
            ans.append(str(i))
            count += 1
            for j in make_divisors(i):
                balls_in_multiple[j] += 1
    print(count)
    if count > 0:
        print(' '.join(ans))


if __name__ == "__main__":
    main()

Solution (Python):
import math
N = int(input())
a_list = [0] + list(map(int, input().split()))
result = True
answer_box = [0] * (N+1)
inboxes = []
for i in range(N, 0, -1):
    last_i = i * (N // i)
    count = 0
    for j in range(last_i, i-1, -i):
        count += answer_box[j]
    if (count % 2) != a_list[i]:
        answer_box[i] = 1
        inboxes.append(i)

if(result):
    print(len(inboxes))
    if(len(inboxes) > 0):
        print(" ".join(str(e) for e in inboxes))
else:
    print(-1)

Solution (Python):
from math import ceil

n = int(input())

a = [0] + [int(x) for x in input().split()]

c = [0 for i in a]

for i in range(n, 0, -1):
    
    curr = 0
    for j in range(i, n+1, i):
        curr += c[j]
    if curr % 2 != a[i]:
        c[i] = 1
    else:
        c[i] = 0


x = c.count(1)

print(x)

for i in range(len(c)):
    if c[i] == 1:
        print(i, end=' ')

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
cur = [0 for i in range(N)]
ball = []
ball_num = 0
for x in range(N):
	i = N-1 - x
	n = i + 1
	if A[i] != cur[i]:
		ball.append(n)
		ball_num += 1
		for j in range(n // 2 + 1):
			m = j + 1
			if m * m > n:
				break
			if n % m == 0:
				cur[j] = 1 - cur[j]
				if n//m != m:
					cur[n//m - 1] = 1 - cur[n//m - 1]  
print(ball_num)
print(" ".join(list(map(str, ball))))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = []
lst = [0] * n
for i, x in reversed(list(enumerate(a))):
  if sum(lst[i::i+1]) % 2 != x:
    lst[i] += 1
    b.append(i+1)
print(len(b))
if len(b) > 0:
  print(*reversed(b))

Solution (Python):
N = int(input())
a_s = [None] + [int(elm) for elm in input().split(" ")]
bs = [None for _ in range(N+1)]

out_indexs = []
out_num = 0
for val in range(N, 0, -1):
    r = N // val
    tmp = [bs[val*i] for i in range(2, r+1)]
    
    other_sums = sum(tmp) % 2
    if other_sums == a_s[val]:
        bs[val] = 0
    else:
        bs[val] = 1
        out_indexs.append(val)
        out_num += 1

print(out_num)
if out_num >= 1:
    print(" ".join(map(str, out_indexs)))

Solution (Python):
N = int(input())
*A, = map(int,input().split())
D = [0]*(N+1)
ans = []
for i in range(N,0,-1):
    if D[i]%2 != A[i-1]:
        ans.append(i)
        for j in range(1,int(i**0.5)+1):
            if i%j==0:
                D[j] += 1
                if i//j != j:D[i//j] += 1
print(len(ans))
print(*ans)

Solution (Python):
N = int(input())
A = [0] + [int(a) for a in input().split()]

ans = [0]*(N+1)

for i in range(N,0,-1):   
    j=2   
    ball = 0
    while(i*j<=N):
        ball += ans[i*j]
        j += 1
    if (ball%2) != A[i]:
        ans[i] = 1 
        
print(sum(ans)) 
for i in range(N+1):
    if ans[i]==1:
        print(i)

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



memo = [0] * N
answer = [0] * N
for i in range(N - 1, -1, -1):
    
    answer[i] = (a[i] + memo[i]) % 2
    if answer[i] == 1:
        for divisor in make_divisors(i+1):
            memo[divisor - 1] += 1

print(sum(answer))

print(' '.join([str(i+1) for i, x in enumerate(answer) if x == 1]))

Solution (Python):
n = int(input())
a = ['null']
a += list(map(int,input().split()))
b = ['null'] + [0 for _ in range(n)]
for i in range(n):
  k = n - i
  d = n // k
  xor = 0
  for di in range(1,d+1):
    xor ^= b[di * k]
  b[k] = a[k] ^ xor
c = []
csum = 0
for i in range(1,n+1):
  if b[i] == 1:
    c.append(str(i))
    csum += 1
print(csum)
print(' '.join(c))

Solution (Python):


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

num = [0 for i in range(N)]
for i in range(N, 0, -1):
        q = N // i
        s = A[i - 1]
        for j in range(2, q + 1):
                s += num[i * j - 1]
                s = s % 2
        num[i - 1] = s

M = sum(num)
print(M)

lst = []
for i in range(N):
        if num[i] == 1:
                lst.append(i+1)
print(' '.join(map(str, lst)))

Solution (Python):
n=int(input())
a_list=list(map(int,input().split()))
a_list=[0]+a_list
ans=[0]*(n+1)
count=0
for i in range(n,0,-1):
    temp=0
    c=n//i
    for j in range(2,c+1):
        temp+=ans[i*j]
    if temp%2==a_list[i]:
        ans[i]=0
    else:
        ans[i]=1
        count+=1
print(count)
for i in range(n+1):
    if ans[i]==1:
        print(i,end='')
        print(' ',end='')

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

b=[0 for _ in range(n)]
for i in range(n):
    y=a[n-i-1]
    b[n-i-1]=y
    divs = make_divisors(n-i)
    for x in divs:
        a[x-1] = a[x-1] ^ y
print(sum(b))
l=[]
for i in range(n):
    if b[i] == 1:
        l.append(i+1)
print(' '.join(map(str,l)))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
L=A[::]
for i in range(N//2,0,-1):
    x=N//i
    s=sum([L[i*k-1] for k in range(1,x+1)])%2
    if L[i-1]!=s: L[i-1]=s
print(sum(L))
L=[str(i+1) for i,c in enumerate(L) if c==1]
print(" ".join(L))

Solution (Python):
n = int(input())
a=list(map(int, input().split()))
ans = a[:]
for i in range(n)[::-1]:
  if i+1 > n//2:
    continue
  add = 0
  for j in range(n):
    add += ans[(j+2)*(i+1)-1]%2
    if (j+3)*(i+1)-1 > n-1:
      break
  ans[i] = add + ans[i]
  ans[i] %= 2
m = sum(ans)
aa = []
for i in range(n):
  if ans[i]:
    aa.append(i+1)
print(m)
print(" ".join(tuple(map(str,aa))))

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
n = getN()
nums = getList()


yaku = [[] for i in range(n + 1)]

for i in range(1, n//2 + 2):
    for j in range(2, n//i + 1):
        yaku[i*j].append(i)


ans = [0 for i in range(n)]

for i in range(n):
    tmp = n - i
    if ans[tmp - 1] != nums[tmp - 1]:
        ans[tmp - 1] = 1
        for y in yaku[tmp]:
            ans[y-1] = (ans[y-1] + 1) % 2
    else:
        ans[tmp - 1] = 0
    


pr = [i + 1 for i, x in enumerate(ans) if x == 1]

print(len(pr))
print(" ".join(list(map(str, pr))))

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
Bs = [-1] * N
for i in reversed(range(N)):
  a = As[i]
  r = 0
  for j in range(2,N+1):
    j2 = j*(i+1)-1
    if j2 >= N:
      break
    r += Bs[j2]
  b = (r+a)%2
  
  Bs[i] = b

Cs = []
for i in range(N):
  if Bs[i] == 1:
    Cs.append(str(i+1))
print(len(Cs))
if len(Cs) > 0:
  print(" ".join(Cs))

Solution (Python):
N = int(input())
a = [0] + list(map(int, input().split()))
b = [None] * (N+1)
for i in range(N//2+1, N+1):
    b[i] = a[i]
for j in range(1, N//2+1)[::-1]:
    if a[j] == 1:
        t = 0
        for i in range(j+j, N+1, j):
            t ^= b[i]
        if t == 1:
            b[j] = 0
        else:
            b[j] = 1
    else:
        t = 0
        for i in range(j+j, N+1, j):
            t ^= b[i]
        if t:
            b[j] = 1
        else:
            b[j] = 0
for i in range(1, N//2+1):
    t = 0
    for j in range(i, N+1, i):
        t ^= b[j]
    if a[i]^t:
        print(-1)
        quit()
ans = [i for i, v in enumerate(b) if v]
print(len(ans))
if len(ans):
    print(*ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = set()
for i in range(n - 1, -1, -1):
    count = 0
    c = i + 1
    while c < 200000:
        if c in b:
            count += 1
        c += (i + 1)
    if count % 2 != a[i]:
        b.add(i + 1)
print(len(b))
print(" ".join(list(map(str, b))))

Solution (Python):
def main():
    n = int(input())
    a = [0] + list(map(int, input().split()))

    b = [0] * (n + 1)
    for i in range(1, n+1)[::-1]:
        cnt = 0
        j = i
        while j <= n:
            if b[j] == 1:
                cnt += 1
            j += i
        if cnt % 2 != a[i]:
            b[i] = 1
    num = sum(b)
    print(num)
    if num != 0:
        print(' '.join([str(i) for i, bb in enumerate(b) if bb == 1]))


main()

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

ans = [0]*N
for i in range(N-1,-1,-1):
    a = 0
    for j in range(2,N//(i+1)+1):
        a += ans[j*(i+1)-1]
    if a%2!=A[i]:
        ans[i] = 1

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

print(' '.join(ans))

Solution (Python):
n = int(input())
a = [int(item) for item in input().split()]

ans = [0] * n
for i, item in enumerate(a[::-1]):
    number = n - i
    total = 0
    for i in range(1, n+1):
        if number * i > n:
            break
        total += ans[number * i - 1]
    if(total % 2 != a[number - 1]):
        ans[number - 1] = 1
ans_num = sum(ans)
print(ans_num)
if ans_num == 0:
    exit()
ret = []
for i, item in enumerate(ans):
    if item == 1:
        ret.append(i+1) 
if len(ans) > 0:
    print(" ".join([str(item) for item in ret]))

Solution (Python):



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

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

    X = list(filter(lambda i: B[i-1] == 1, range(1, N+1)))

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



if __name__ == '__main__':
    main()

Solution (Python):
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  
  

n = inn()
a = inl()
b = [0] * (n+1)
cnt = 0
for i in range(n,0,-1):
    sum = 0
    for j in range(i*2,n+1,i):
        sum += b[j]
    if sum%2 != a[i-1]:
        b[i] = 1
        cnt += 1
print(cnt)
for i in range(1,n+1):
    if b[i]==1:
        printn(str(i)+' ')
print("")

Solution (Python):
N = int(input())
A = [0] + list(map(int, input().split()))
B = [0] * (N + 1)
for i in reversed(range(1, N + 1)):
  s = 0
  for j in range(2, N // i + 1):
    s += B[i * j]
  if s % 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())
a=list(map(int,input().split()))
l=[0]*n
for i in range(n-1,-1,-1):
    x=l[i:n:i+1]
    if a[i]==x.count(1)%2:
        l[i]=0
    else:
        l[i]=1
print(l.count(1))
ans=[]
for i in range(n):
    if l[i]==1:
        ans.append(i+1)
ans=map(str,ans)
print(" ".join(ans))

Solution (Python):
import numpy as np

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

ans = [0 for i in range(n)]

arr.reverse()

for i in range(n):
    base = n-i
    sup = n//base
    now = 0
    for j in range(1,sup+1):
        now += ans[base*j-1]
    if now%2 == arr[i]%2:
        ans[base-1]=0
    else:
        ans[base-1]=1



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

Solution (Python):
n = int(input())
a = [0]
for x in input().split():
	a.append(int(x))
x = [0] * (n + 1)

i = n
while i > 0:
	x[i] = a[i]
	j = 2 * i
	while j <= n:
		x[i] += x[j]
		x[i] %= 2
		j += i
	i -= 1

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

Solution (Python):
N = int(raw_input()) + 1
A = [None] + map(int, raw_input().split())

ans = [0 for i in xrange(N)]



for i in range(N - 1, 0, -1):
    ind = i + i
    xor = A[i]
    while ind < N:
        xor ^= ans[ind]
        ind += i
    ans[i] = xor

print sum(ans)
for i in range(1, N):
    if ans[i]: print i,

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
memo = {}
memo[n] = 0
ans = []
for i in range(n)[::-1]:
    tmp = i + 1
    tmp2 = 2 * tmp
    cnt = 0
    while tmp2 <= n:
        cnt += memo[tmp2]
        tmp2 += tmp
    if cnt % 2 == 1 and a[i] == 0:
        ans.append(tmp)
        memo[tmp] = 1
    elif cnt % 2 == 0 and a[i] == 1:
        ans.append(tmp)
        memo[tmp] = 1
    else:
        memo[tmp] = 0
print(len(ans))
print(" ".join(map(str, ans)))

Solution (Python):
N = int(input())
a_s = [int(n) for n in input().split()]

boxes = [0] * N
for i, a in enumerate(reversed(a_s)):
    i = N - i
    if a != sum(boxes[i - 1::i]) % 2:
        boxes[i-1] = 1

print(boxes.count(1))
for i, b in enumerate(boxes, 1):
    if b == 1:
        print(i)

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

N = int(input())
A = [None] + [int(x) for x in input().split()]

answer = []
choose = [0] * (N+1)

for n in range(N,0,-1):
    x = sum(choose[2*n::n])
    if x % 2 == A[n]:
        continue
    choose[n] += 1
    answer.append(str(n))

print(len(answer))
print(' '.join(answer))

Solution (Python):
def solve():
  N = int(input())
  A = [int(i) for i in input().split()]
  B = [ False ] * N
  for i in range(N - 1, -1, -1):
    count = 0
    for j in range(N // (i + 1)):
      if B[(j + 1) * (i + 1) - 1]:
        count += 1
    if count % 2 != A[i]: B[i] = True

  print(B.count(True))
  for i in range(N):
    if B[i]: print(i + 1)

solve()

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
b = [0]*(N+1)
for i in range(N, 0, -1):
    temp = 0
    for j in range(1, N//i+1):

        temp += b[j*(i)]
    if temp % 2 != a[i-1]:
        b[i] = 1

print(b.count(1))
ans = []
for i in range(N):
    if b[i+1] == 1:
        ans.append(i+1)

print(" ".join(map(str, ans)))

Solution (Python):
N=list(map(int, input().split()))
N=N[0]
a=list(map(int, input().split()))
b=[0]*(N+1)
ball=0
for i in range(N,0,-1):
    ans=0
    index=i*2
    while index<=N:
        ans+=b[index]
        index+=i
    if ans%2!=a[i-1]:
        b[i]=1
        ball+=1

print(ball)
moji=""
for i in range(1,N+1):
    if b[i]==1:
        moji+=str(i)+" "
print(moji)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    a = [0]+list(map(int,input().split()))

    res = [0]*(n+1)
    b = []
    for i in range(n,0,-1):
        e = a[i]
        p = 0
        v = i
        while v <= n:
            p += res[v]
            v += i
        if p%2 != e:
            res[i] = 1
            b.append(i)
    print(len(b))
    for e in b:
        print(e,end=' ')

if __name__ == '__main__':
    main()

Solution (Python):



import sys  
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools



sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe


def local_input():
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)


def solve():
    n = int(input())
    a = list(map(int,input().split()))
    a = [0] + a
    
    for i in range(n,0,-1):
        x = 0
        for j in range(1,(n//i) +1):
            x += a[i*j]
        a[i] = x % 2
    
    m = a.count(1)

    print(m)
    for i in range(1,n+1):
        if a[i] == 1:
            print(i)

    return 0

if __name__ == "__main__":
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

Solution (Python):
def yakusu(n):
    results = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            results.append(i)
            results.append(n // i)
    return results

N = int(input())
A = list(map(int, input().split()))
is_odd = [False for i in range(N+1)]
A.insert(0, 0)
ans = []
for i in range(N, 0, -1):
    if A[i] == 1:
        if not is_odd[i]:
            ans.append(i)
            for y in set(yakusu(i)):
                is_odd[y] = not is_odd[y]
    elif A[i] == 0:
        if is_odd[i]:
            ans.append(i)
            for y in set(yakusu(i)):
                is_odd[y] = not is_odd[y]
print(len(ans))
if len(ans) != 0:
    print(' '.join(map(str, ans)))

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N = int(input())
a = inpl()
s = [0]*N
for i in range(N,0,-1):
    s[i-1] = (sum(s[d*i-1] for d in range(2,N//i+1)) + a[i-1])  % 2
print(sum(s))
ans = " ".join([ str(i+1) for i in range(N) if s[i] ])
if len(ans) > 0:
    print(ans)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = [0] * N
for i in range(N - 1, -1, -1):
  ai = A[i]
  for j in range(i, N, i + 1):
    ai ^= B[j]
  B[i] = ai
print(sum(B))
if sum(B):
  print(' '.join([str(i + 1) for i in range(N) if B[i]]))

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

n = int(input())
aa = list(map(int, input().split()))
counts = {}
balls = {}


for i in range(len(aa)):
    if aa[i] == 1:
        counts[i + 1] = 1
    else:
        counts[i + 1] = 0

for i in range(n, 0, -1):
    
    if counts[i] % 2 == 0:
        continue
    
    balls[i] = True
    ds = divisors(i)
    for d in ds:
        counts[d] += 1
balls = list(balls.keys())
print(len(balls))
if len(balls) > 0:
    print(' '.join(map(str, balls)))

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

Solution (Python):
import math


def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))
    cnt = [0] * (N+1)
    ans = []
    for i in range(N, 0, -1):
        if cnt[i] != A[i]:
            ans.append(i)
            mx = int(math.sqrt(i))
            for j in range(1, mx+1):
                if i % j == 0:
                    cnt[j] ^= 1
                    if j ** 2 != i:
                        cnt[i // j] ^= 1
    print(len(ans))
    if len(ans):
        print(*ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = [None] + list(map(int, input().split()))

balls = [None] + ([0] * N)


def ball_in(i):
    k = 2
    n = 0
    while k * i <= N:
        n += balls[k * i]
        k += 1
    return 0 if n % 2 == A[i] else 1

for i in range(N, 0, -1):
    balls[i] = ball_in(i)

M = 0
B = []
for i, b in enumerate(balls[1:]):
    if b == 1:
        M += 1
        B.append(str(i + 1))

print(M)
print(" ".join(B))

Solution (Python):
def solve():
    N = int(input())
    a = [0]+list(map(int, input().split()))
    box = [0]*(N+1)
    for i in range(N//2+1, N+1):
        box[i]=a[i]
    for i in range(1, N//2+1)[::-1]:
        res = 0
        for j in range(2, N//i+1):
            res+=box[j*i]
        box[i] = (res+a[i])%2
        
    print(sum(box))
    for i in range(1, N+1):
        if box[i]==1:
            print(i)
solve()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [None]*N

for n in range(N, 0, -1):
    B[n-1] = A[n-1]
    k=n*2
    while k<=N:
        B[n-1] ^= B[k-1]
        k += n

M = sum(B)
print(M)
if M>0:
    print(' '.join( [str(i+1) for i,b in enumerate(B) if b==1] ))

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




arr = [0] * (N+1)
ans = []
for i in range(N, 0, -1):
  a = (sum(arr[i::i])+A[i]) % 2
  arr[i] = a
  if a:
    ans.append(i)
print(len(ans))
if len(ans):
  print(' '.join(list(map(str, ans))))