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()))
b = [0] * n
count = 0

if sum(a) == 0:
    print(0)
    exit()


for i in range(1, n+1):
    if i == n:
        if a[0] == 1 and sum(b) % 2 == 0:
            b[0] = 1
            count += 1
        elif a[0] == 0 and sum(b) % 2 == 1:
            b[0] = 1
            count += 1
    elif a[n-i] == 1 and sum(b[n-i::n-i+1]) % 2 == 0:
        b[n-i] = 1
        count += 1
    elif a[n-i] == 0 and sum(b[n-i::n-i+1]) % 2 == 1:
        b[n-i] = 1
        count += 1


if count == 0:
    print(-1)
else:
    print(count)
    for i in range(len(b)):
        if b[i] == 1:
            print(i+1, end=' ')

Solution (Python):
n = int(input())
a = [0]
a.extend(list(map(int, input().split())))
ans = [0 for _ in range(n+1)]
for i in range(n//2 + 1, n + 1):
    ans[i] = a[i]
for j in range(2, n+1):
    for i in range(n//(j+1) + 1, n//j + 1):
        if sum([ans[k*i] for k in range(2, j+1)]) % 2 != a[i]:
            ans[i] = 1
answer = [i for i, x in enumerate(ans) if x == 1]
l = len(answer)
print(l)
for i in range(l):
    if i <= l-2:
        print(answer[i], end=" ")
    else:
        print(answer[i])

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []

N = I()
A = LI()
dp = [0]*N

for i in range(N-1,-1,-1):
    judge = int(0)
    if A[i]==1:
        judge +=1
    k = int(i + 1)
    while k < N:
        k += (i+1)
        if k<N+1 and dp[k - 1] == 1:
            judge += 1





    dp[i] = judge%2


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

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

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

    box = [0 for _ in range(n+1)]
    result = []
    for i in range(n, 0, -1):
        counter = 0
        for j in range(1, (n//i)+1):
            counter += box[j*i]
        if counter % 2 != a[i-1]:
            box[i] = 1
            result.append(i)
    """
    for i in range(1, n+1):
        counter = 0
        for j in range(1, (n//i)+1):
            counter += box[j*i]
        if counter%2 != a[i-1]:
            print(-1)
            sys.exit()
    """
    print(len(result))
    if len(result) != 0:
        print(*result[::-1])  
if __name__ == '__main__':
    main()

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

box = [0 for _ in range(n+1)]
result = []
for i in range(n, 0, -1):
    counter = 0
    for j in range(1, (n//i)+1):
        counter += box[j*i]
    if counter % 2 != a[i-1]:
        box[i] = 1
        result.append(i)
for i in range(1, n+1):
    counter = 0
    for j in range(1, (n//i)+1):
        counter += box[j*i]
    if counter%2 != a[i-1]:
        print(1)
        sys.exit()

print(len(result))
if len(result) != 0:
    print(*result[::-1])

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

box = [0 for _ in range(n+1)]
result = []
for i in range(n, 0, -1):
    counter = 0
    for j in range(1, (n//i)+1):
        counter += box[j*i]
    if counter % 2 != a[i-1]:
        box[i] = 1
        result.append(i)
for i in range(1, n+1):
    counter = 0
    for j in range(1, (n//i)+1):
        counter += box[j*i]
    if counter%2 != a[i-1]:
        print(-1)
        sys.exit()

print(len(result))
if len(result) != 0:
    print(*result[::-1])

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = [0] * n
    ans = []
    for i in range(n-1, -1, -1):
        t = 0
        for j in range(i, n, (i+1)):
            t += ls[j]
        if t % 2 != a[i]:
            ls[i] = 1
            ans.append(i + 1)
    print(len(ans))
    if len(ans) != 0:
        print(*ans)


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
answer = []
for i in range(N, 0, -1):
  if A[i-1] == 1:
    count = 1
    number = 0
    while count*i <= N:
      number += B[count*i-1]
      count+=1
    if number%2 == 0:
      B[i-1] = 1
      answer.append(i)
  else:
    count = 1
    number = 0
    while count*i <= N:
      number +=B[count*i-1]
      count+=1
    if number%2==1:
      B[i-1] = 1
      answer.append(i)
print(B.count(1))
print(*answer)

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

ball = [0]*N

for i in reversed(range(N)):
    Sum = 0
    x = 2
    while((i+1)*x <= N):
        Sum += ball[(i+1)*x-1]
        x += 1

    ball[i] = (Sum + a[i]) % 2

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

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

ans = [0 for i in range(n)]
for num in range(n,0,-1):
  cnt = 0
  for nu in range(num-1,n,num):
    cnt += ans[nu]
  if lis[num-1] != cnt % 2:
    ans[num-1] = 1
cnt1 = 0
for num in range(n):
  if ans[num] == 1:
    cnt1 += 1
print(cnt1)
for i in range(n):
  if ans[i] == 1:
    print(i+1,end = " ")

Solution (Python):
N=int(input())
AL=list(map(int, input().split()))
L=[]
for i in range(N-1,-1,-1):
    s=AL[i]
    for j in range((i+1)*2-1,N,i+1):
        s^=AL[j]
    AL[i]=s
    if AL[i]==1:
        L.append(i+1)
print(len(L))
if L:
    print(*L)

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

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

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

memo = [0]*n
ans_list = []
memo_count = 0
for i in range(n-1,-1,-1):
	if (i+1)*2 <= n:
		memo_count = 0
		for j in range(2,n//(i+1)+1):
			memo_count += memo[(i+1)*j-1]
		if memo_count%2 != list1[i]:
			memo[i] = 1
			ans_list.append(i+1)

	else:
		if list1[i] == 1:
			memo[i] = 1
			ans_list.append(i+1)

ans_list.sort()

print(len(ans_list))
print(" ".join(map(str,ans_list)))

Solution (Python):


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

count=0
ans=[]
hako=[0]*N
for i in range(N)[::-1]:
    all=0
    for j in range(i,N)[::i+1]:
        if i==j:
            continue
        all^=hako[j]
    if all==1:
        if A[i]==1:
            continue
        else:
            hako[i]=1
            count+=1
            ans.append(i+1)
    else:
        if A[i]==1:
            hako[i]=1
            count+=1
            ans.append(i+1)
        else:
            continue
ans.sort()
print(count)
print(*ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
flag = [-1] * (N+1)
answer_list = []
for i in range(N):
    counter = 0
    i_num = N - i
    for j in range(i_num, N+1, i_num):
        if j == i_num:
            continue
        else:
            if flag[j] == 1:
                counter += 1
    if counter % 2 == A[i_num - 1]:
        flag[i_num] = 0
    else:
        flag[i_num] = 1
        answer_list.append(i_num)
print(len(answer_list))
if answer_list:
    print(" ".join(map(str, answer_list)))

Solution (Python):


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


a_list = [0] + a_list
b_list = [0] * (N + 1)



for i in range(N):
    
    idx = N - i
    total = sum(b_list[idx : N + 1 : idx])

    if total % 2 != a_list[idx]:
        b_list[idx] = 1

idx_list = [str(i) for i, b in enumerate(b_list) if b == 1]
ans = sum(b_list[1:])
print(ans)
if ans != 0:
    print(" ".join(idx_list))

Solution (Python):
import bisect

def solve():
    N = int(input())
    a = list(map(int, input().split()))
    b = []
    c = [0] * (N)

    M = 0

    for i in range(N - 1, -1, -1):
        if i >= N // 2:
            if a[i] == 1:
                b.append(i+1)
                c[i] = 1
                M += 1
            else:
                c[i] = 0
        else:
            num = i
            cnt = 0
            j = 2
            while (i+1) * j <= N:
                num = (i+1) * j
                cnt += c[num-1]
                j += 1
            if cnt % 2 == 0:
                if a[i] == 0:
                    c[i] = 0
                else:
                    b.append(i+1)
                    c[i] = 1
                    M += 1
            else:
                if a[i] == 0:
                    b.append(i+1)
                    c[i] = 1
                    M += 1
                else:
                    c[i] = 0
    
    print(M)
    if M != 0:
        print(*b)
    
    


if __name__ == '__main__':
    solve()

Solution (Python):
import math

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

for i in range(n-1):
  ptr = n - 1 - i
  if a[ptr] % 2 == 1:
    a[0] += 1
    for j in range(2, int(math.sqrt(ptr+1))+1):
      if (ptr + 1) % j == 0:
        a[j-1] += 1
        if (ptr + 1) // j != j:
          a[(ptr + 1) // j - 1] += 1
      
cnt = 0
que = []
for  i in range(n):
  if a[i] % 2 == 1:
    cnt += 1
    que.append(i+1)

print(cnt)
if cnt > 0:
  print(' '.join(map(str, que)))

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
'''
1 ~ N の倍数の箱を見ていくがN ~ 1の順で決めていく
'''
ans = [-1 for i in range(N)]
opt = []
for i in range(N,0,-1):
    p = N // i
    if p >= 2 :
        m = 0
        for x in range(2,p+1,1):
            m += ans[x*i-1]
        m = m % 2
        if m == A[i-1]:
            ans[i-1] = 0
        else :
            ans[i-1] = 1
            opt.append(i)
    else :
        if A[i-1] == 0 :
            ans[i-1] = 0
        else:
            ans[i-1] = 1
            opt.append(i)
print(sum(ans))
print(*opt)

Solution (Python):
N = int(input())
*A, = map(int, input().split())
B = [0 for _ in range(N)]
ans = []
for i in reversed(range(1, N+1)):
    temp = 0
    for j in range(2*i, N + 1, i):
        temp ^= B[j-1]
    if A[i-1] != temp: B[i-1] = 1; ans.append(i)
print(len(ans))
print(*ans)

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

Solution (Python):




N = int(input())
a = [-1] + list(map(int, input().split()))

box = [-1] + [0]*N

for idx in reversed(range(1,N+1)):
    if sum([box[i] for i in range(idx, N+1, idx)]) % 2 == a[idx]:
        box[idx] = 0
    else:
        box[idx] = 1

print(sum(box[1:]))
for idx in range(N+1):
    if box[idx] == 1:
        print(idx)

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

b=[0]*(N+1)
M=0

for i in range(N,0,-1):
    cnt = 0

    for j in range(i+i,N+1,i):
        if b[j] == 1:
            cnt += 1

    if a[i-1]==1 and cnt%2==0:
        b[i]=1
        M+=1
    elif a[i-1]==0 and cnt%2==1:
        b[i]=1
        M+=1
        

print(M)
for i in range(1,N+1):
    if b[i]==1:
        print(i,end=" ")

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
c = []


for i in reversed(range(n)):
    sum_i = sum(b[i::i+1])
    if not sum_i % 2 == a[i]:
        b[i] = 1
        c.append(i+1)

print(sum(b))
if c:
    print(' '.join(map(str, c)))

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
b = [0]*n
c = []

for i in range(n):
    if sum(b[n-i-1:n:n-i]) % 2 != a[n-i-1]:
        b[n-i-1] += 1
        c.append(n-i)
print(len(c))
print(' '.join(map(str, c[::-1])))

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

b = [0] * N
M = 0
ans = []
for i in range(N, 0, -1):
    count = a[i-1]
    x = 2
    while x * i <= N:
        count += b[x*i-1]
        x += 1
    if count % 2 == 1:
        b[i-1] = 1
        M += 1
        ans.append(i)


print(M)
print(*ans)

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


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

if a.count(1) == -1:
    print(0)
else:
    print(b.count(1))
    print(' '.join(map(str, [i for i, x in enumerate(b) if x == 1])))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

for n in range(N//2,0,-1):
    A[n] = sum(A[n::n])&1

I = [i for i,x in enumerate(A) if x]

print(len(I))
if len(I) > 0:
    print(' '.join(map(str,I)))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import reduce
from operator import xor

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

for n in range(N//2,0,-1):
    A[n] = reduce(xor,A[n::n],0)

I = [i for i,x in enumerate(A) if x]

print(len(I))
if len(I) > 0:
    print(' '.join(map(str,I)))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import reduce
from operator import xor

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

B = [0] * (N+1)
for n in range(N,0,-1):
    s = reduce(xor,B[n+n::n],0)
    B[n] = s^A[n]

I = [i for i,x in enumerate(B) if x]

print(len(I))
if len(I) > 0:
    print(' '.join(map(str,I)))

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
for i in reversed(range(N)):
  k= N // (i+1)
  tmp=0
  for j in range(1,k):
    tmp+=b[(i+1)*(j+1)-1]
  b[i]=abs((tmp%2)-a[i])
M=sum(b)
ans=[]
for i in range(N):
  if b[i]==1:
    ans.append(i+1)
print(M)
print(" ".join(map(str,ans)))

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


ans = [0 for _ in range(N + 1)]
out = []
for idx in range(N, 0, -1):
	count = 0
	rep = 1
	while(idx * rep <= N):
		count += ans[idx * rep]
		rep += 1
		
	if A[idx] != count % 2:
		ans[idx] = 1
		out.append(idx)

print(len(out))
if(len(out)>0):
	print(" ".join(map(str, out)))

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


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

print(len(ans))
print(*ans)

Solution (Python):
from collections import defaultdict
N = int(input())
arr = list(map(int, input().split()))
puts = []
dd = defaultdict(int)

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

for i in range(1,N+1)[::-1]:
    if N//2 < i and arr[i-1] == 1:
        puts.append(i)
        ds = make_divisors(i)
        for j in ds:
            dd[j] += 1
    else:
        
        c = dd[i]
        if (c % 2 == 0 and arr[i-1] == 1) or (c % 2 == 1 and arr[i-1] == 0):
            puts.append(i)
            ds = make_divisors(i)
            for j in ds:
                dd[j] += 1

print(len(puts))
if len(puts):
    print(" ".join(map(str, sorted(puts, reverse=True))))

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

    B = [0] * (N+1)

    for i in range(N,0,-1):
        tmp = 0
        for j in range(i,N+1,i):
            tmp ^= B[j]
        B[i] = tmp ^ A[i]

    cnt = 0
    ans = []
    for i in range(1,N+1):
        if B[i] == 1:
            cnt += 1
            ans.append(i)

    print(cnt)
    print(*ans)

main()

Solution (Python):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    res = [0 for i in range(n)]
    lres = []
    for i in range(n,0,-1):
        flag = 0
        t = i*2
        while t <= n:
            flag = flag ^ res[t-1]
            t = t+i
        if a[i-1] != flag:
            res[i-1] = 1
            lres.append(str(i))

    print(len(lres))
    if len(lres) != 0:
        print(" ".join(lres))

main()

Solution (Python):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    res = [0 for i in range(n)]
    lres = []
    for i in range(n,0,-1):
        l = []
        flag = 0
        t = i*2
        while t <= n:
            flag = flag ^ res[t-1]
            t = t+i
        if a[i-1] != flag:
            res[i-1] = 1
            lres.append(str(i))

    print(len(lres))
    if len(lres) != 0:
        print(" ".join(lres))

main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
res = [0 for i in range(n)]
lres = []
for i in range(n,0,-1):
    l = []
    flag = 0
    t = i*2
    while t <= n:
        flag = flag ^ res[t-1]
        t = t+i
    if a[i-1] != flag:
        res[i-1] = 1
        lres.append(str(i))

print(len(lres))
if len(lres) != 0:
    print(" ".join(lres))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
res = [0 for i in range(n)]
for i in range(n,n//2,-1):
    res[i-1] = a[i-1]

for i in range(n//2,0,-1):
    l = []
    flag = 0
    t = i*2
    while t <= n:
        flag = flag ^ res[t-1]
        t = t+i
    if a[i-1] != flag:
        res[i-1] = 1

if res == [0 for i in range(n)]:
    print(0)
else:
    lres = []
    for i in range(n):
        if res[i] == 1:
            lres.append(str(i+1))
    print(len(lres))
    print(" ".join(lres))

Solution (Python):
N = int(raw_input())
A = list(map(int,raw_input().split()))
ans = [0]*N
for i in reversed(range(0, N)):
  ball = 0
  for j in range(i,N,i+1):
    ball = ball + ans[j]
  if (ball+A[i])%2!=0 :
    ans[i] = 1
print sum(ans)
if sum(ans) != 0:
  for i in range(0,len(ans)):
    if ans[i] != 0:
      print i+1,

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

b = [0 for x in range(N)]

for i in reversed(range(N)):
    j = i + 1
    tmp = 0
    while j <= N:
        tmp += b[j - 1]
        j += i + 1
    if (tmp + a[i]) % 2 == 1:
        b[i] = 1

M = sum(b)
print(M)
if M != 0:
    for i in range(N):
        if b[i] == 1:
            print(i + 1, end=' ')
    print('\n')

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

c = [-1] + [0] * n

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

for i in range(n // 2, 0, -1):
  sum = 0
  j = i + i
  while (j <= n):
    sum += c[j]
    j += i
  c[i] = (a[i] - sum) % 2

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

Solution (Python):



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









b = [0 for _ in range(N)]


for i in range(N - 1, 0 , -1):
    
    
    
    
    
    
    if (a[i] + sum(b[i::i+1])) % 2 == 0:
        b[i] = 0
    else:
        b[i] = 1

if a[0] == 0:
    b[0] = (sum(b[1:])) % 2
else:
    
    b[0] = (sum(b[1:]) + 1) % 2




s = sum(b)
print(s)
if s != 0:
    
    print(*[x + 1 for x in range(N) if 0 < b[x]])

Solution (Python):
N = int(input())
mod_arr = list(map(int,input().split()))
arr = [0]*N
in_arr = []

for i in range(N,0,-1):
  if i > N//2:
    if mod_arr[i-1] == 0:
      continue
    else:
      arr[i-1] = 1
      in_arr.append(str(i))
      
  else:
    S = 0
    for j in range(2*i,N+1,i):
      S += arr[j-1]
    if S%2 == mod_arr[i-1]:
      arr[i-1] = 0
    else:
      arr[i-1] = 1
      in_arr.append(str(i))

print(len(in_arr))
print(' '.join(in_arr))

Solution (Python):
def main():
    N = int(input())
    lst_a = list(map(int, input().split()))
    ans = set()

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


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    lst_a = list(map(int, input().split()))
    ans = set()

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


if __name__ == "__main__":
    main()

Solution (Python):


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

m = 0
ans = [0]*(n+1)



i=1
for i in range(n,0,-1):
    sum_num = 0
    for j in range(i,n+1,i):
        sum_num += ans[j]

    if((sum_num & 1) != a_s[i-1]):
        m += 1
        ans[i] = 1

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

print(m)
print(' '.join(map(str,ans2)))

Solution (Python):

import math
 






 
N = int(input()) 
 

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



 

 

 
if N%2==0:
    first = int(N/2)-1
else:
    first = int((N-1)/2)-1


for i in range(first,-1,-1): 
    
    
    multiple_list = [(i+1)*j for j in range(1,1+N//(i+1))]
    
    
    
    
    total = sum([ans[j-1] for j in multiple_list])
    
    if ans[i]==1 and total%2==0:
        ans[i] = 0
    elif ans[i]==0 and total%2==1:
        ans[i] = 1
        

print(sum(ans))
print(' '.join(map(str,[j+1 for j in range(0,N) if ans[j]==1])))

Solution (Python):


import sys
def input():
    return sys.stdin.readline()[:-1]

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

flag=[-1]*N 
ans=[]
for i in range(N-1,-1,-1):
    cnt=0
    for j in range(i,N,i+1): 
        if j==i:
            continue
        else:
            if flag[j]==1:
                cnt+=1
    if (A[i]+cnt)%2==0: 
        flag[i]=0
    else:
        flag[i]=1
        ans.append(i+1) 
num=len(ans)
if num==0: 
    print(0)
else: 
    print(num)
    print(*ans)

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

ans=[]
box=[0]*N

for i in reversed(range(1,N+1)):
  asum=sum(box[i-1::i])
  if asum%2+A[i-1]==1:
    box[i-1]=1
    ans.append(i)

print(len(ans))
print(*ans)

Solution (Python):


n=int(input())
a=[0]+list(map(int,input().split()))
b=[0]+[0]*n

for i in range(n):
    idx=n-i
    j=2
    cnt=0
    while idx*j<=n:
        cnt+=b[idx*j]
        j+=1
    cnt%=2
    if cnt==a[idx]:continue
    b[idx]=1
    
smb=sum(b)
print(smb)
for i in range(1,n+1):
    if b[i]:print(i,end=' ')
if smb:print()

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

for i in range(N//2+1,N+1):
    B[i] = A[i]

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

B.pop(0)

print(sum(B))
ans=[]
for i in range(len(B)):
    if B[i]==1:
        ans.append(i+1)

print(*ans)

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

Solution (Python):
def md(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[:1]+divisors[2:]

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

for i in range(N)[::-1]:
  a = A[i]
  if a % 2:
    ans.append(i+1)
  D = md(i+1)
  
  for d in D:
    A[d-1] += a
    
print(len(ans))
print(*ans)

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

divisors = [[] for _ in range(N + 1)]

for i in range(1, N + 1):
    num = 2 * i
    while num <= N:
        divisors[num].append(i)
        num += i
ans = []
balls = [0] * (N + 1)
A = [int(x) for x in input().split()]
for i in reversed(range(1, N+1)):
    if balls[i] != A[i-1]:
        ans.append(i)
        balls[i] ^= 1
        for d in divisors[i]:
            balls[d] ^= 1

print(len(ans))
if ans:
    print(*ans)

Solution (Python):
n = input()
a = [0] + map(int, raw_input().split())
b = [0 for _ in range(n + 1)]
used = []

for i in xrange(n, 0, -1):
  sum = 0
  for j in xrange(2 * i, n + 1, i):
    sum += b[j]
  if sum % 2 != a[i]:
    used.append(i)
    b[i] = 1
print len(used)
for x in used: print x,
print

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
box = [0] * n
ans = []

for i in range(n-1, -1, -1):
    ms = sum(box[i::i+1])
    if ms % 2 != a[i]:
        box[i] = 1
        ans.append(i+1)

print(len(ans))
print(*ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = []
k = 2
for i in range(n, 0, -1):
    if n/k < i:
        for x in range(2, k):
            a[i-1] += a[x * i - 1]
        a[i-1] = a[i-1] % 2
    else:
        while n/k >= i:
            k += 1
        else:
            for x in range(2, k):
                a[i-1] += a[x * i - 1]
            a[i-1] = a[i-1] % 2
    if a[i-1] == 1:
        ans.append(i)
print(len(ans))
print(*ans)

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):
  tmp=0
  for j in range(2,N//i+1):
    if B[i*j]: tmp+=1
  B[i]=(A[i]+tmp)%2
  

C=[]
for i in range(1,N+1):
  if B[i]: C.append(i)


print(len(C))
if len(C): print(*C)

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def divisors(m: int):
    i = 1
    div = []
    while i * i <= m:
        if m % i == 0:
            div.append(i)
            div.append(m // i)
        i += 1

    return list(set(div))

n = ni()
a = list(li())
b = [0]*n
ans = []
for i in range(n-1, -1, -1):
    if a[i] != b[i]:
        divs = divisors(i+1)
        ans.append(i+1)
        for j in divs:
            b[j-1] += 1
            b[j-1] %= 2

print(len(ans))

if ans:
    print(*ans[::-1])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
counts = [0] * (N + 1)
ball_counts = 0
balls = []
for i in range(N-1, -1, -1):
    if sum(counts[::i+1][1:]) % 2 != A[i]:
        ball_counts += 1
        balls.append(i+1)
        counts[i+1] = 1
print(ball_counts)
if ball_counts > 0:
    print(*balls)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = LI()
A = [0] * n
total = 0
for i in range(n - 1, -1, -1):
    ret = 0
    for j in range((i + 1) * 2 - 1, n, i + 1):
        ret += A[j]
    if L[i] != ret % 2:
        A[i] = 1
        total += 1



print(total)
for k in range(n):
    if A[k]:
        print(k + 1)

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

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

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n, *a = map(int, open(0).read().split())

    a = [0] + a
    b = [0] * (n + 1)
    for i in range(1, n+1)[::-1]:
        if i * 2 > n:
            b[i] = a[i]
        else:
            rem = 0
            for j in range(i * 2 , n + 1, i):
                rem = rem ^ b[j]
            b[i] = rem ^ a[i]

    b = b[1:]
    m = sum(b)
    print(m)
    for i, cur_b in enumerate(b, start=1):
        if cur_b == 1:
            print(i, end=' ')
    return()

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
zeros = [0] * N
length = len(a)

for i, ai in zip(a[::-1], range(length, -1, -1)):
    s = 0
    for j in range(ai, length+1, ai):
        s += zeros[j-1]
    if s % 2 == i:
        pass
    else:
        zeros[ai-1] = 1

print(sum(zeros))
for i, v in enumerate(zeros, 1):
    if v:
        print(i, end=" ")

Solution (Python):
n=int(input())
a= list(map(int, input().split()))
li=[0 for _ in range(n)]
for i in range(n-1,-1,-1):
    check=0
    for j in range(n//(i+1)):
        check^=li[(i+1)*(j+1)-1]
    if check!=a[i]:
        li[i]+=1
ans=[i+1 for i, x in enumerate(li) if x == 1]
print(len(ans))
print(" ".join(map(str,ans)))

Solution (Python):
n=int(input())
a= list(map(int, input().split()))
li=[0 for _ in range(n)]
for i in range(n-1,-1,-1):
    check=0
    for j in range(n//(i+1)):
        check^=li[(i+1)*(j+1)-1]
    if check!=a[i]:
        li[i]+=1
ans=[i+1 for i, x in enumerate(li) if x == 1]
print(len(ans))
print(" ".join(map(str,ans)))

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
zeros = [0] * N
ai = length = len(a)

for i in a[::-1]:
    s = 0
    for j in range(ai, length+1, ai):
        s += zeros[j-1]
    if s % 2 == i:
        pass
    else:
        zeros[ai-1] = 1
    ai -= 1

print(sum(zeros))
for i, v in enumerate(zeros, 1):
    if v:
        print(i)