Problem:


Score : 400 points

Problem Statement

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

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

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

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

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

Constraints

All values in input are integers.

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

a_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

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

M
b_1 b_2 ... b_M

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

Sample Input 1

3
1 0 0

Sample Output 1

1
1

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

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

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

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

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

Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

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



Sample input:
3
1 0 0


Sample output:
1
1

Submission status: Accepted

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

temp = [0]*N
for i in range(N-1,-1,-1):
  for j in [0,1]:
    temp[i] = j
    if sum(temp[i::i+1])%2 == A[i]:
      break
  else:
    print(-1)
    exit()
print(sum(temp)) 
anslist = []
for i in range(N):
  if temp[i] == 1:
    anslist.append(i+1)
if anslist == []:
  exit()
else:
  print(*anslist)
  exit()

Submission status: Accepted

Solution code:
import sys

N = int(input())

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

b = [0] * (N+1)

num = 0

for i in range(N, 0, -1):
    sum = 0
    for j in range(i+i, N+1, i):
        if j < len(a):
            sum ^= b[j]
        else:
            break

    b[i] = sum ^ a[i]
    if b[i] == 1:
        num += 1

print(num)

if num == 0 or num == -1:
    sys.exit(0)

flag = False

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

print("")

Submission status: Accepted

Solution code:
N = int(input())
a = [0] + list(map(int, input().split()))
b = [0]*(N+1)

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = [0] + list(map(int, input().split()))
b = [0]*(N+1)

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

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

print(len(ans))
for i in range(0, len(ans)):
  if i == len(ans) - 1:
    print(ans[i])
  else:
    print(ans[i], end=" ")

Submission status: Accepted

Solution code:
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)


# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

def divisor_list(n):
    ret = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
        i += 1
    return ret


N = int(input())
tmp = [int(x) for x in input().split()]
A = [-999]
for a in tmp:
    A.append(a)

B = []

for i in range(N, 0, -1):
    # print(i)
    if A[i] == 1:
        B.append(str(i))
        DL = divisor_list(i)
        for j in DL:
            A[j] = (A[j] + 1) % 2

print(len(B))
print(" ".join(B))

pass

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int, input().split()))
n=N//2
b=[None]*N
for i in range(n,N):
        b[i]=a[i]
for i in range(n-1,-1,-1):
        c=0
        t=2*i+1
        while t<N:
                if b[t]==1:
                        c+=1
                t+=(i+1)
        b[i]=(c+a[i])%2
print(b.count(1))
for i in range(N):
        if b[i]==1:
                print(i+1,end=" ")

Submission status: Accepted

Solution code:

n = int(input())

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

#mid = n//2 + n%2

#print(* range(10)[::2] )

ans = [0]*(n+1)

for _ in range(n):# 0 ... n-1
    i = n-_ # n ... 1

    ta = sum(ans[i::i])
    ans[i] = 0 if ta%2 == an[i-1] else 1

#    print(i, an[i-1::i])


m = sum(ans)
print(m)

if m > 0:
    print(*[i for i, x in enumerate(ans) if x >0])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i in reversed(range(n)):
    x = i + 1
    cnt = 0
    for j in range(x + x, n + 1, x):
        cnt += b[j - 1]
    b[i] = (cnt + a[i]) % 2
ans = []
for i in range(n):
    if b[i]:
        ans.append(i + 1)
print(len(ans))
print(*ans)

Submission status: Accepted

Solution code:
# ABC134D - Preparing Boxes
# Better ver.
def main():
    n = int(input())
    A = [0] + list(map(int, input().rstrip().split()))
    ans = []  # answer "in any order"
    ans_append = ans.append
    for i in range(n, 0, -1):
        A[i] = sum(A[i::i]) % 2
        if A[i]:
            ans_append(i)
    print(len(ans))
    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
for i in range(n,0,-1):
    a[i-1] = sum(a[i-1::i])%2
print(sum(a))
print(' '.join([str(i+1) for i,j in enumerate(a) if j == 1]))

Submission status: Accepted

Solution code:
# ABC134D - Preparing Boxes
# Better ver.
def main():
    n = int(input())
    A = [0] + list(map(int, input().rstrip().split()))
    for i in range(n // 2, 0, -1):  # second half: no multiples
        A[i] = sum(A[i::i]) % 2
    ans = [i for i, j in enumerate(A) if j]
    print(len(ans))  # all cells: [1] -> len() (much faster than sum())
    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC134D - Preparing Boxes
def main():
    n = int(input())
    A = [0] + list(map(int, input().rstrip().split()))
    B = [0] * (n + 1)
    for i in range(n, 0, -1):
        cnt, p = 0, 2
        while i * p <= n:
            cnt += B[i * p]
            p += 1
        if cnt % 2 != A[i]:
            B[i] += 1
    total = sum(B)
    if total == 0:
        print(0)
    else:
        print(total)
        print(*(i for i, j in enumerate(B[1:], start=1) if j == 1))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=list(map(int,input().split()))
bb=[0]*len(aa)
for i in range(n):
    j = n-i-1
    s = sum(bb[j::j+1])
    if s % 2 != aa[j]:
       bb[j] = 1
print(sum(bb))
print(' '.join(str(i+1) for i in range(len(bb)) if bb[i]))

Submission status: Accepted

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

ret = [0] * N

for i in range(N-1, -1, -1) :
    s = a[i]
    for j in range(i, N, i + 1) :
        s ^= ret[j]
    ret[i] = s
    
b = []
for i in range(N) :
    if ret[i] :
        b.append(i+1)

print(len(b))
print(' '.join([str(i) for i in b]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
n = int(input())
num_list = [ int(v) for v in input().split() ]
ans_list = [ 0 ] * n
for i in range(n-1,-1,-1):
 
    if sum(ans_list[i::i+1]) % 2 == num_list[i]:
        ans_list[i] = 0
    else:
        ans_list[i] = 1
 
print(sum(ans_list))
for i in range(n):
 
    if ans_list[i] == 1:
        print(i+1)

Submission status: Accepted

Solution code:
N = int(input())

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

B = [0] * (N+1)

for i in range(N, 0, -1):
    
    x = 2
    _sum = 0
    for j in range(i+i, N+1, i):    
        _sum ^= B[j]

    B[i] = _sum ^ A[i-1]

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

if ans:
    print(len(ans))
    print(' '.join(map(str, ans)))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
ans_list = [0] * (N)
ans = []
for i in range(N):
    summ = 0
    j = N - i
    while j < N:
        j = j + N - i
        if j - 1 < N:
            summ += ans_list[j-1]
    if (summ % 2) != arr[N - i - 1]:
        ans_list[N - i - 1] = 1
        ans.append(N - i)

ans.sort()
print(len(ans))
for i in range(len(ans)):
    if i == len(ans)-1:
        print(ans[i])
    else:
        print(ans[i],'', end="")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ball = [0]*n
for i in range(n, 0, -1):
    cnt = 0
    for j in range(i * 2, n + 1, i):
        cnt += ball[j-1]
    cnt %= 2
    if cnt != a[i - 1]:
        ball[i - 1] = 1
print(ball.count(1))
for i in range(0, n):
    if ball[i] == 1:
        print(i+1, end=" ")

Submission status: Accepted

Solution code:
def d_preparing_boxes(N, A):
    boxes = [0] * (N + 1)
    result = []

    for i in range(N, 0, -1):
        # N以下のiの倍数(i自身を除く)の箱に入っているボールの数を求める
        total = 0
        for j in range(1, N // i):
            total += boxes[(j + 1) * i]
        # 求めたボール数と条件の偶奇が一致しないなら、i番の箱にボールを入れる
        if total % 2 != A[i - 1]:
            boxes[i] = 1
            result.append(i)
    return '\n'.join(map(str, [len(result)] + result)) if len(result) != 0 else 0

N = int(input())
A = [int(i) for i in input().split()]
print(d_preparing_boxes(N, A))

Submission status: Accepted

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

M = [0 for _ in range(N)]
for i in range(N-1, -1, -1):
    total = 0
    n = 2
    while (i+1) * n <= N:
        total += M[(i+1)*n-1]
        n += 1

    if total % 2 == A[i]:
        M[i] = 0
    else:
        M[i] = 1


print(sum(M))

kugiri = False
for i in range(len(M)):
    if M[i] == 1:
        if kugiri:
            print(" ", end="")
        print(i+1, end="")
        kugiri = True
print()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = a.copy()

for i in range(n//2, 0, -1):
  if(a[i-1] != sum(b[i-1::i])%2):
    b[i-1] = 1 - a[i-1]
print(sum(b))
print(*(i+1 for i, x in enumerate(b) if x))

Submission status: Accepted

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

idxs = [i for i in range(N,0,-1)]
box=[0 for _ in range(N)]

for idx in idxs:
    div = [(i+1)*idx for i in range(N//idx)]
    sum_=sum([box[c-1] for c in div])
    if sum_ % 2 != l[idx-1]:
        box[idx-1] = 1
    
print(sum(box))
for i, v in enumerate(box):
    if v==1:
        print(i+1, end=' ')

Submission status: Accepted

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

if set(a) <= {0,1}:
    for i in range(N//2, -1, -1):
        ball_sum = sum(b[i::i+1])
        if ball_sum % 2 == a[i]:
            continue
        else:
            b[i] = int(not(b[i]))
        
    print(sum(b))
    for j in range(N-1, -1, -1):
        if b[j]: print(j+1)

else: print(-1)

Submission status: Accepted

Solution code:
N,*A=map(int,open(0).read().split())
for n in range(N):A[N-n-1]=sum(A[N-n-1::N-n])%2
print(sum(A),'\n',*(i+1 for i,x in enumerate(A) if x))

Submission status: Accepted

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

    for i in range(N):
        A[N - i] = sum(A[N - i :: N - i]) % 2

    print(sum(A))
    print(*(i for i, v in enumerate(A) if v))

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

lst = [0]*N
for i in range(N, 0, -1):
    tmp = 0
    for j in range(i-1, N, i):
        tmp += lst[j]
    if A[i-1]!=tmp%2:
        lst[i-1]=1
print(sum(lst))
for idx, e in enumerate(lst):
    if e==1:
        print(idx+1, end= ' ')

Submission status: Accepted

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

for i in range(N//2, -1, -1):
    ball_sum = sum(b[i::i+1])
    if ball_sum % 2 == a[i]:
        continue
    else:
        b[i] = int(not(b[i]))

print(sum(b))
for j in range(N-1, -1, -1):
    if b[j]: print(j+1)

Submission status: Accepted

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

j = 0
while i>0:
    sum1=0
    j = i + i
    while j<=N:
        sum1 += B[j-1]
        sum1=(sum1+2)%2
        j=j+i
    B[i-1]+=(A[i-1]+sum1)
    B[i-1]=(B[i-1]+2)%2
    i=i-1
count=0
for s in B:
  if s == 1 :
    count+=1
print(count)
for i in range(N):
  if B[i]==1:
    print(i+1,end=" ")

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline

n = int(input())
num_list = [ int(v) for v in input().split() ]
ans_list = [ 0 ] * n

for i in range(n-1,-1,-1):

    if sum(ans_list[i::i+1]) % 2 == num_list[i]:
        ans_list[i] = 0
    else:
        ans_list[i] = 1

print(sum(ans_list))
for i in range(n):

    if ans_list[i] == 1:
        print(i+1)

Submission status: Accepted

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

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

for i in range(N):
    base = N - 1 - i
    for j in range(base, N, base+1):
        if j == base:
            ans[i] += A[j]
        else:
            ans[i] -= ans[N - 1 - j]
        ans[i] = ans[i] % 2
        if ans[i] < 0:
            print('-1')
            break

else:
    ans_ids = [str(i+1) for i, a in enumerate(reversed(ans)) if a % 2 == 1]
    print(len(ans_ids))
    print(' '.join(ans_ids))

Submission status: Accepted

Solution code:
N = int(input())
A = [0]+list(map(int, input().split()))
for n in range(N):
  A[N-n]=sum(A[N-n::N-n])%2
print(sum(A),'\n',*(i for i, x in enumerate(A) if x))

Submission status: Accepted

Solution code:
N=int(input())
A=[Ai for Ai in map(int,input().split())]
B=[]
for i in range (N//2+1,N+1):
    if A[i-1]==1:
        B.append(i)

for i in range (1, N//2+1)[::-1]:
    A[i-1]=sum(A[i-1::i])%2
    if A[i-1]==1:
        B.append(i)

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

Submission status: Accepted

Solution code:
import math

N=int(input())
a=list(map(int, input().split()))
H=math.floor(N / 2)
B=a[:]

for i in range(H-1,-1,-1):
    s = 0
    j = i
    j+=(i+1)
    while j < N:
        s+=B[j]
        j+=(i+1)
    m = s % 2
    B[i] = a[i] ^ m

ans = [i + 1 for i, x in enumerate(B) if x == 1]
l = len(ans)
print(l)
if (l > 0):
    print(*ans)

Submission status: Accepted

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

hako = [0] * (N+1)

for i in range(1,N+1)[::-1]:
    count = 0
    for j in range(i,N+1,i):
        if j%i == 0:
            count += hako[j]

    if count % 2 == a[i-1]:
        hako[i] = 0
    else:
        hako[i] = 1

print(sum(hako))

if sum(hako):
    ans = []
    for i, bin in enumerate(hako):
        if bin:
            ans.append(i)
    print(*ans)

Submission status: Accepted

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

hako = [0] * (N+1)

for i in range(1,N+1)[::-1]:
    if i > N / 2:
        if a[i-1] == 1:
            hako[i] = a[i-1]
    else:
        count = 0
        for j in range(i,N+1,i):
            if j%i == 0:
                count += hako[j]

        if count % 2 == a[i-1]:
            hako[i] = 0
        else:
            hako[i] = 1

print(sum(hako))

if sum(hako):
    ans = []
    for i, bin in enumerate(hako):
        if bin:
            ans.append(i)
    print(*ans)

Submission status: Accepted

Solution code:
import math

N=int(input())
a=list(map(int, input().split()))
B=a[:]

for i in range(N-1,-1,-1):
    s = 0
    j = i
    j+=(i+1)
    while j < N:
        s+=B[j]
        j+=(i+1)
    m = s % 2
    B[i] = a[i] ^ m

ans = [i + 1 for i, x in enumerate(B) if x == 1]
l = len(ans)
print(l)
if (l > 0):
    print(*ans)

Submission status: Accepted

Solution code:
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
A = list(map(int, input().split()))


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

counter = [0] * N
ballNum = 0
boxWithBall = []

for i in range(N - 1, -1, -1):
	if counter[i] != A[i]:
		ballNum += 1
		boxWithBall.append(i + 1)
		
		for j in makeDivisors(i + 1):
			counter[j - 1] ^= 1
			
print(ballNum)

for i in boxWithBall:
	print(i, end=' ')

Submission status: Accepted

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

ans = [0]*(N+1)

for i in range(1, N + 1)[::-1]:
    sum_ans = sum(ans[x] for x in range(i, N + 1, i))
    if sum_ans % 2 != A[i - 1]:
        ans[i] = 1
        
print(sum(ans))
# print(ans)

prt = []
if sum(ans) > 0:
  for i, v in enumerate(ans):
    if v != 0:
      prt.append(i)
  print(*prt)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N//2+1, 0, -1):
  sum = 0
  for o in range(1, (N//i)+1):
    sum += A[i*o-1]
  A[i-1] = sum%2
  
print(A.count(1))
ans = [str(q) for q,w in zip(range(1, N+1), A) if w == 1]
print(" ".join(ans))

Submission status: Accepted

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

    divisors.sort()
    return divisors[:-1]

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    # N = 200000
    # A = [1,0] * 100000
    B = [-1]*N
    dic = {}
    rest = N
    for i in reversed(range(1,N+1)):
        B[i-1] = A[i-1]
        rest -= 1
        div = make_divisors(i)
        for d in div:
            A[d-1] += B[i-1]
            rest -= 1
    B = [b % 2 for b in B]
    res = []
    for i, b in enumerate(B):
        if b == 1:
            res.append(str(i+1))
    print(len(res))
    print(" ".join(res))
main()

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().strip().split())))
b = [0] * (n+1)
for i in range(n):
    b[i+1] = a[i]

#print(b)

#print('p',n//2)
for i in reversed(range(1,n//2 + 1)):
    j = 2
    b_sum = 0
    #print(i)
    while i * j <= n:
        #print(i,j)
        b_sum += b[i*j]
        j += 1
    if (b_sum % 2) == a[i-1]:
        b[i] = 0
    else:
        b[i] = 1

#print(b)

s = sum(b)

print(s)
if s > 0:
    sl = ''
    for i in range(len(b)):
        if b[i] == 1:
            sl += str(i) + ' '

    print(sl[:-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC134 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

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

b = [0]*(n+1)

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

for i in range(1,n//2+1)[::-1]:
    s = 0
    if i == 1:
        if sum(b) == 0 and a[0]:
            b[1] = 1
        elif sum(b) % 2 != a[0]:
            b[1] = 1
        break
    for j in range(2,n):
        if i*j > n:
            break
        if b[i*j] == 1:
            s += 1
    if s % 2:
        if a[i-1] == 1:
            continue
        b[i] = 1
    elif s % 2 == 0 and a[i-1] == 1:
        b[i] = 1

m = sum(b)
if m == 0:
    print(0)
    quit()
else:
    print(m)
    ans = [i for i,v in enumerate(b) if v]
    print(*ans)

Submission status: Accepted

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

b = [0]*n

for i in range(n):
    c = []
    j=2
    while (n-i)*j<=n:
        c.append((n-i)*j)
        j+=1
    if len(c)==0:
        b[n-i-1]=a[n-i-1]
    else:
        d = a[n-i-1]
        for x in c:
            d+=b[x-1]
        if d%2==1:
            b[n-i-1]=1
        else:
            b[n-i-1]=0

ans = []


for i in range(n):
    if b[i]%2==1:
        ans.append(i+1)
print(len(ans))
for i in range(len(ans)):
    print(ans[i],end=' ')

Submission status: Accepted

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

result = [0] * N
for i in range(N):
    if A_list[N - i - 1] == 1 and (N - i) * 2 > N:
        result[N - i - 1] = 1
    if A_list[N - i - 1] == 0 and (N - i) * 2 > N:
        result[N - i - 1] = 0
    if A_list[N - i - 1] == 1 and (N - i) * 2 <= N:
        tmp_sum = 0
        for r in range(N - i - 1, N, N - i):
            tmp_sum += result[r]
        if tmp_sum % 2 == 0:
            result[N - i - 1] = 1
        if tmp_sum % 2 == 1:
            result[N - i - 1] = 0
    if A_list[N - i - 1] == 0 and (N - i) * 2 <= N:
        tmp_sum = 0
        for r in range(N - i - 1, N, N - i):
            tmp_sum += result[r]
        if tmp_sum % 2 == 0:
            result[N - i - 1] = 0
        if tmp_sum % 2 == 1:
            result[N - i - 1] = 1

print(sum(result))
for i, r in enumerate(result):
    if r == 1:
        print(i + 1)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
for n in range(N):
  B[N-n]=(sum(B[::N-n])%2+A[N-n-1])%2
print(sum(B),'\n',*(i for i, x in enumerate(B) if x))

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
r=range(n)
for i in r:a[~i]=sum(a[~i::n-i])%2
print(sum(a),*[i+1for i in r if a[i]])

Submission status: Accepted

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

ans = [0 for x in range(N+1)]
ans_m = 0
ans_a = []
for i in range(N,0,-1):
    s = 0
    for j in range(2*i,N+1,i):
        if ans[j] == 1:
            s += 1
    if s & 1 != A[i-1]:
        ans[i] = 1
        ans_m += 1
        ans_a.append(i)

print(ans_m)
if ans_m > 0:
    print(" ".join(map(str,ans_a)))

Submission status: Accepted

Solution code:
"""
from collections import defaultdict
from collections import deque

def prime(N):
    se = [0,0,1]+[1]*(N-2)
    n = 2
    while n ** 2 <= N:
        if se[n]:
            nn = 2*n
            while nn <= N:
                se[nn] = 0
                nn += n
        n += 1

    return [x for x in range(0,N+1) if se[x]]
"""
N = int(input())
A = list(map(int,input().split()))

# N = 1のときはコーナーケース！

if N == 1:
    if A[0] == 1:
        print(1)
        print(1)
    else:
        print(0)
    exit()

#deq = deque()

"""
pr = prime(N)

deq = deque(pr)
deq.appendleft(1)

cnt = len(deq)

d = [0]*(N+1)
d[1] = -1
for p in pr:
    d[p] = -1

B = pr
while cnt < N:
    C = []
    for num in B:
        if num * 2 > N:
            break
        for p in pr:
            if num * p > N:
                break
            aaa = num * p
            if d[aaa] <= 0:
                d[aaa] = p
                deq.append(aaa)
                C.append(aaa)
                cnt += 1
    B = sorted(C)
"""
B = [0]*N

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

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

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
r=range(n)
for i in r[::-1]:a[i]=sum(a[i::i+1])%2
print(sum(a),*[i+1for i in r if a[i]])

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
for i in range(n,0,-1):a[i-1]=sum(a[i-1::i])%2
print(sum(a),*[i+1for i in range(n)if a[i]])

Submission status: Accepted

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




def sol(i,want):
    num=N//(i+1)
    wa=B[i]

    for j in range(num):
        k=i+j*(i+1)
        wa+=B[k]
#         print(i,wa,B[i])
#         print((i+1)+j*(i+1)-1)
#     print(i,wa,B[i])
    wa=wa%2
#     print(i,wa,A[i])
    
    if wa==want:
        x=0
    else:
        x=1
#     print(num)
    return x 

B=A[:]
half=N//2
for i in range(half):
    j=half-1-i
#     print(j)
    B[j]=sol(j,A[j])
    
C=[i+1 for i, x in enumerate(B) if x ==1]

m=sum(B)
print(m)
print(*C)

Submission status: Accepted

Solution code:
import sys
line = sys.stdin.readline
M = int(line())
b = list(map(int, line().split()))
c = [0] * M
for i in range(M, 0, -1):
    ball = 0
    for j in range(2, M+1):
        if i * j > M:
            break
        ball += c[i * j - 1]
    c[i - 1] = (b[i - 1] + ball) % 2
ans = []
for i, v in enumerate(c):
    if v == 1:
        ans.append(i + 1)
print(len(ans))
print(*ans)

Submission status: Accepted

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

ans = [0 for x in range(N+1)]
for i in range(N,0,-1):
    s = 0
    for j in range(2*i,N+1,i):
        if ans[j] == 1:
            s += 1
    ans[i] = s & 1 != A[i-1]

ans_m = 0
ans_a = []
for i in range(len(ans)):
    if ans[i]:
        ans_m += 1
        ans_a.append(i)

print(ans_m)
if ans_m > 0:
    print(" ".join(map(str,ans_a)))

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
b=[0]*-~n
for i in range(n,0,-1):b[i]=(sum(b[j]for j in range(i,n+1,i))+a[i-1])%2
c=[i for i in range(n+1)if b[i]]
print(len(c),*c)

Submission status: Accepted

Solution code:
import math

N = int(input())

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

bb = aa[:]

i = N

while i > 0:

    total = 0
    j = i * 2

    while j <= N:
        total ^= bb[j - 1]
        j += i

    bb[i - 1] = total ^ aa[i - 1]
    i -= 1

bbKisu = list(filter(lambda n: n % 2 == 1, bb))
count = len(bbKisu)

print(count)
for i in range(N):
    if bb[i] == 1:
        print(i + 1)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
b=[0]*-~n
for i in range(n,0,-1):
    t=0
    for j in range(i,n+1,i):
        t+=b[j]
    b[i]=(t+a[i-1])%2
c=[i for i,b in enumerate(b)if b]
print(len(c),*c)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]
for i in range(n-1, -1, -1):
	tmp = 0
	for j in range(2*(i+1)-1, n, i+1):
		tmp ^= b[j]
	b[i] = a[i]^tmp
ans = [i+1 for i in range(n) if b[i]]
print(len(ans))
print(*ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

from math import ceil

n = int(input())
a = list(map(int,input().split()))
b = ['0'] * (n+1)
    
for i in reversed(range(0, n)):
    d = n // (i+1)
    cn = 0
    for j in range(2, d+1):
        if b[j*(i+1)] == '1':
            cn += 1
    if cn % 2 == a[i]:
        b[i+1] = '0'
    else:
        b[i+1] = '1'
print(b.count('1'))
ee = []
for i,v in enumerate(b):
    if i == 0:
        continue
    if v == '1':
        ee.append(str(i))
print(' '.join(ee))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.insert(0,0)
b = [0] * (N + 1)
ans = []
count = 0
for i in reversed(range(1,N + 1)):
  if a[i] == 1:
    sumi = 0
    j = 2
    while True:
      if (i * j) > N:
        break
      sumi += b[i * j]
      j += 1
    if sumi % 2 == 0:
      b[i] = 1
      count += 1
      ans.append(int(i))
  else:
    sumi = 0
    j = 2
    while True:
      if (i * j) > N:
        break
      sumi += b[i * j]
      j += 1
    if sumi % 2 == 1:
      b[i] = 1
      count += 1
      ans.append(int(i))
#ans.sort()
print(count)
print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
import math

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

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

ans = [index for index, v in enumerate(a) if v == 1]
print(len(ans))
print(*ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.insert(0,0)
b = [0] * (N + 1)
ans = []
count = 0
for i in reversed(range(1,N + 1)):
  if a[i] == 1:
    sumi = 0
    j = 2
    while True:
      if (i * j) > N:
        break
      sumi += b[i * j]
      j += 1
    if sumi % 2 == 0:
      b[i] = 1
      count += 1
      ans.append(int(i))
  else:
    sumi = 0
    j = 2
    while True:
      if (i * j) > N:
        break
      sumi += b[i * j]
      j += 1
    if sumi % 2 == 1:
      b[i] = 1
      count += 1
      ans.append(int(i))
ans.sort()
print(count)
print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
flag=[-1]*n
ans=[]
for i in range(n-1,-1,-1):
  cnt=0
  for j in range(2*i+1,n,i+1):
    if flag[j]==1:
      cnt+=1
  if (arr[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)

Submission status: Accepted

Solution code:
n=int(input())
A=tuple(map(int,input().split()))
B=[0]*n
for i in reversed(range(n)):
    k=i+1
    l=n//k
    tmp=0
    for j in range(2,l+1):
        idx=k*j-1
        tmp^=B[idx]
    B[i]=tmp^A[i]
Ans=[]
for i,b in enumerate(B):
    if b:
        Ans.append(i+1)
print(len(Ans))
print(*Ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [0] + list(map(int, input().split()))
for i in range(n // 2, 0, -1):
    a[i] = sum(a[i::i]) % 2
print(sum(a))
print(*(i for i, b in enumerate(a) if b))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    a = [0]
    a.extend( list(map(int,input().split())) )
    tmp = [0]*(n+1)
    ans = []
    for i in range(n,0,-1):
        sum = 0
        for j in range(i+i,n+1,i):
            sum = sum^tmp[j]
        tmp[i] = sum^a[i]
    for i in range(1,n+1):
        if(tmp[i]>0):
            ans.append(i)
    
    print(len(ans))
    s = ' '.join([str(n) for n in ans])
    print(s)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
a = input()
b = [None] * (n + 1)
r = []
for i in range(n, 0, -1):
    b[i] = (ord(a[2 * i - 2]) + sum(b[i * 2::i])) % 2
    if b[i]:
        r.append(i)
print(len(r))
print(*r)

Submission status: Accepted

Solution code:
n = int(input())
a = [0] + list(map(int, input().split()))
for i in range(n // 2, 0, -1):
    a[i] = sum(a[i::i]) % 2
print(sum(a))
print(*(i for i, b in enumerate(a) if b))