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()))

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

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

Submission status: Accepted

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

ans = [0] * n

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 reversed(range(n)):
    if li[i] == 1:
        ans[i] = 1
        for j in make_divisors(i+1):
            li[j-1] = (li[j-1] + 1) % 2

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

Submission status: Accepted

Solution code:

n = int(input())
a = [0] + [int(i) for i in input().split()]
retval = [0] * (n+1)

for i in range(n,0,-1):
    p = sum([retval[x] for x in range(i+i,n+1,i)])
    retval[i] = (p%2) ^ a[i]

print(sum(retval))
print(" ".join(str(i) for i in range(1,n+1) if retval[i]))

Submission status: Accepted

Solution code:

n = int(input())
a = [0] + [int(i) for i in input().split()]
b = [0] * (n+1)

for i in range(1,n+1)[::-1]:
    mul_sum = sum((b[x] for x in range(i+i,n+1,i)))
    b[i] = (mul_sum%2) ^ a[i]

print(sum(b))
print(" ".join(str(i) for i in range(1,n+1) if b[i]))

Submission status: Accepted

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

for i in reversed(range(1,N+1)):
    count = 0
    total = 0
    # 倍数
    for j in range(i, N+1, i):
        count += 1
        total += ans[j-1]
    # 倍数が一つのとき
    if count == 1:
        if nums[i-1] == 0:
            ans[i-1] = 0
        else:
            ans[i-1] = 1
    # 倍数が複数ある
    else:
        # 指定が偶数
        if nums[i-1] == 0:
            if total % 2 != 0:
                ans[i-1] = 1
        else:
            if total % 2 == 0:
                ans[i-1] = 1


# 出力フォーマット処理
result = [i+1 for i in range(len(ans)) if ans[i] == 1]
result = [str(i) for i in result]
print(len(result))
print(" ".join(result))

Submission status: Accepted

Solution code:
N = int(input())
A = [0]+[int(x) for x in input().split()]
res = [0]*(N+1)
sum_res = 0
for i in range(N):
    # 今見てるところ
    k = N-i
    tmp = 0
    for j in range(k,N+1,k):
       	tmp += res[j]
    res[k] = A[k] ^ tmp%2
    sum_res += res[k]
 
print(sum_res)
print(' '.join([str(i) for i,x in enumerate(res) if x==1]))

Submission status: Accepted

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

ans = []
for i in range(n):
    if i < n//2:
        ans.append(0)
    else:
        ans.append(a[i])

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

print(ans.count(1))
for i in range(n):
    if ans[i] != 0:
        print(i+1, "", end="")

Submission status: Accepted

Solution code:
n=int(input())
balls=list(map(int,input().split()))
ans=[0]*n;m=0;al=[]
for i in range(n)[::-1]:
  d=i+1
  c=n//d
  mal=2
  check=0
  while d*mal<=n:
    check+=ans[d*mal-1]
    mal+=1
  check%=2
  if check!=balls[i]:
    ans[i]=1
    al.append(str(d))
    m+=1
print(m)
print(" ".join(al))

Submission status: Accepted

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

B = [0] * N

out = []
for idx in range(N, 0, -1):
    a = A[idx - 1]

    q = N // idx

    cnt = 0
    for j in range(2, q + 1):
        if B[idx * j - 1] == 1:
            cnt += 1

    r = cnt % 2

    if a == 0:
        if r == 1:
            B[idx - 1] = 1
            out.append(idx)
        else:
            B[idx - 1] = 0
    else:
        if r == 1:
            B[idx - 1] = 0
        else:
            B[idx - 1] = 1
            out.append(idx)

g = sum(B)
print(g)

if g != 0:
    print(*out)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int, input().split()))
box=[0]*n
for i in range(n-1,-1,-1):
    if n//(i+1)<=1 and A[i]==1:
        box[i]=1
    elif n//(i+1)<=1 and A[i]==0:
        pass
    elif n//(i+1)>1:
        if A[i]==sum(box[2*(i+1)-1::(i+1)])%2:
            pass
        elif A[i]!=sum(box[2*(i+1)-1::(i+1)])%2:
            box[i]=1
ans=""
cnt=0
for i in range(n):
    if box[i]==1:
        ans+=str(i+1)+" "
        cnt+=1
if cnt==sum(box):
    print(sum(box))
    print(ans)
else:print("-1")

Submission status: Accepted

Solution code:
#134
N=int(input())
a=list(map(int,input().split()))
b_l=[1]*N
b_ll=[]
for i in range(N,0,-1):
    b_i=0
    j=i
    while j<=N:
        b_i+=b_l[j-1]
        j+=i     
    if b_i%2 != a[i-1]:
        b_l[i-1]-=1
    else:
        b_ll.append(i)
print(sum(b_l))
print(*b_ll)

Submission status: Accepted

Solution code:
N = int(input())
inf = input().split()
A = {i+1:int(inf[i]) for i in range(N)}
ans = [0 for i in range(N+1)]
keys = list(A.keys())
keys.sort(reverse=True)
for k in keys:
  count = 0
  for j in range(2*k, N+1, k)[::-1]:
    count += ans[j]
  ans[k] = (A[k]-(count%2))%2
value = sum(ans)
print(value)
if value>0:
  tag = []
  for i in range(N+1):
    if ans[i]:
      tag += [str(i)]
  print(' '.join(tag))

Submission status: Accepted

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

b_list = [0 for _ in range(N)]
c_list = []
for i in range(N,0,-1):
  # print(i)
  tmp = sum(b_list[i-1::i]) # i-1 番以降の N の倍数を取り出す
  # print(i, b_list[i-1::i])
  if tmp %2 != a_list[i-1]: # 偶奇が合っているかを確認
    b_list[i-1] = 1
    c_list.append(str(i))
if len(c_list)!=0:
  print(len(c_list))
  print(" ".join(c_list))
elif all(elem == 0 for elem in a_list):
  print("0")
else:
  print("-1")

Submission status: Accepted

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

patternlist=[None for i in range(n)]


#まず、n/２より大きい番号に入る玉の数は一通り
for i in range(n//2,n):
    if a[i]==0:
        patternlist[i]=0
    else:
        patternlist[i]=1
# print(patternlist)

#次に、小さい玉から順にやっていく
for i in range(0,n//2):
    i=n//2-1-i
    sumnum=0
    num=i+1
    multiply=1
    while True:
        multiply+=1
        if num*multiply>n:
            break
        sumnum+=patternlist[num*multiply-1]
        sumnum=sumnum%2
        
    if sumnum==a[i]:
        patternlist[i]=0
    else:
        patternlist[i]=1
    
        
    
print(patternlist.count(1))
for i in range(n):
    if patternlist[i]==1:
        print(i+1)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [0 for _ in range(N)]
C = []
for i in range(N,0,-1):
    tmp = sum(B[i-1::i])
    if tmp%2!=A[i-1]:
        B[i-1] = 1
        C.append(str(i))
print(len(C))
if len(C)!=0:
    print(" ".join(C))

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):
    j = 2
    c = 0
    while (i + 1) * j <= n:
        c += b[(i + 1) * j - 1]
        j += 1
    b[i] = 0 if (c % 2 == a[i]) else 1
print(sum(b))
for i in range(len(b)):
    if b[i]:
        print(i + 1, end = ' ')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    # 1-indexに
    a = [0] + list(map(int, input().split()))
    c = [0 for _ in range(n + 1)]

    # See
    # https://www.youtube.com/watch?v=-o4r74eJzV4
    # 全体の計算量は，O(N^2)のようにみえて，O(NlogN)
    # 箱iの番号が大きいものから見る
    for i in range(n, 0, -1):
        # ボールの個数の和を0で初期化
        ball_count = 0

        # iの倍数の箱を順番に見る
        # ループの範囲を[2 * i, n]として，i個飛ばしで
        for j in range(2 * i, n + 1, i):
            # mod2は，xor（排他的論理和）を使うと言い換えるとスマートに記述できる．
            # ただし，演算の順序に注意が必要
            ball_count ^= c[j]

        # i個ずつみた後の合計(mod2)とa[i]を比べる
        c[i] = a[i] ^ ball_count

    # 出力
    # ボールが入っている箱の個数とその番号
    ans = [index for index, ci in enumerate(c) if ci == 1]
    print(len(ans))
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

Submission status: Accepted

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


answer = []
B = 0

for i in range(N):
    U = N - i
    L = N // (U)
    if L == 1:
        answer.append(a[U-1])
    else:
        for j in range(L-1):
            t = U * (j+1)
            B += answer[-t]
        B = B % 2
        if B == a[U-1]:
            answer.append(0)
        else:
            answer.append(1)
    B = 0


k = 0



answer.reverse()
print(answer.count(1))
J = len(answer)
for i in range(J):
    if answer[i] == 1:
        print(i+1, end=' ')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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 * i, N + 1, i):
        tmp += b[j]
        tmp %= 2

    b[i] = tmp ^ a[i]

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

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

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, 0, -1):
    if sum(b[i-1::i])%2 != a[i-1]:
        b[i-1] = 1

c = [i+1 for i in range(n) if b[i] == 1]
if len(c) != 0:
    print(len(c))
    print(*c)
else:
    print("0")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int,input().split()))
c = 0
x = []
k = [0]*a
for i in range(a-1,-1,-1):
    souwa = 0
    for j in range(i,a,i+1):
        souwa += k[j]
    if not souwa%2 == b[i]:
        k[i] = 1
        c += 1
        x.append(i+1)
print(c)
if len(x) > 0:
    for o in range(len(x)):
        print(x[o],' ',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())
A = [int(x) for x in input().split()]
A = [0] + A

R = []

for i in range(N, 0, -1):
    if A[i] == 1:
        R.append(i)
        dl = divisor_list(i)
        for j in dl:
            A[j] = (A[j] + 1) % 2

print(len(R))
print(" ".join([str(i) for i in R]))

# print(R)

Submission status: Accepted

Solution code:
def pbox(n,a):
    count = 0
    result = []
    x=[0]*n
    for i in xrange(n,0,-1):
        total = 0
        for j in xrange(i,n+1,i):
            total += x[j-1]
        if  total % 2 != a[i-1]:
            x[i-1]=1
            result.append(i)
        else:
            pass
 
    print len(result)
    print ' '.join(map(str,result))
 
if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())
 
    pbox(n,a)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

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

    ans_num = 0
    ans = ""
    box = [0] * (N)
    for i in range(N-1, -1, -1):
        total = 0
        for j in range(i, N, i+1):
            # iの倍数のボールの個数の和を計算する
            total += box[j]
        if total%2 == A[i]:
            continue
        else:
            ans_num += 1
            ans += str(i+1) + " "
            box[i] = 1
    
    # 検査する
    for i in range(N-1, -1, -1):
        total = 0
        for j in range(i, N, i+1):
            total += box[j]
        if total%2 == A[i]:
            continue
        else:
            print(-1)
            return

    print(ans_num)
    if ans_num != 0:
        print(ans[0:-1])

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = [0] * a
e = 0
f = []
for i in range(a - 1, -1, -1):
    d = 0
    for j in range(i, a, i + 1):
        d += c[j]
    if d % 2 != b[i]:
        c[i] = 1
        e += 1
        f.append(str(i + 1))
print(e)
if e > 0:
    f.sort()
    print(" ".join(f) if e > 1 else f[0])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [False] * n
for i in range(n - 1, -1, -1):
    if sum(b[i::i+1]) % 2 != a[i]:
        b[i] = True
res = [str(x + 1) for x, v in enumerate(b) if v]
print(len(res))
if len(res) > 0:
    print(' '.join(res))

Submission status: Accepted

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

def main():
	n = int(input().strip())
	a = []
	a.append(0)
	a.extend(list(map(int, input().strip().split())))
	s = [0] * (n+1)
	for i in reversed(range(1, n+1)):
		j = 1
		d = 0
		while i * j <= n:
			d += s[i*j]
			j += 1
		s[i] = (d+a[i]) % 2
	M = sum(s)
	print(M)
	for i in range(n+1):
		if s[i] == 1:
			print("{} ".format(i), end="")
	print("")

if __name__ == '__main__':
	main()

Submission status: Accepted

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

b = set()
d = dict()
for i in range(n, 0, -1):
    x = i * 2
    count = 0
    while x <= n:
        count += d[x]
        x += i
    if a[i] == 0:
        if count % 2 == 1:
            b.add(i)
            d[i] = 1
        else:
            d[i] = 0
    else:
        if count % 2 == 0:
            b.add(i)
            d[i] = 1
        else:
            d[i] = 0

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

Submission status: Accepted

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

# print(n)
# print(a)
# if n==1:
#     m = 1
#     b = a[0]

h = int(np.floor(n/2))
# print("h={}".format(h))
boxes = np.zeros(n)
boxes[h:] = a[h:]
if n%2==0:       
    for i in range(h):
        d = n-h-i-1
        s = sum(boxes[2*(d+1)-1::d+1])%2
        if s==a[d]:
            boxes[d] = 0
        else:
            boxes[d] = 1
    # print("ans_even={}".format(boxes))
    ans = list(map(int, boxes))
    print(sum(ans))
    for i in range(len(ans)):
        if ans[i]==1:
            print("{} ".format(i+1), end="")
else:
    for i in range(h):
        d = n-h-i-2
        s = sum(boxes[2*(d+1)-1::d+1])%2
        if s==a[d]:
            boxes[d] = 0
        else:
            boxes[d] = 1
    # print("ans_odd={}".format(boxes))
    ans = list(map(int, boxes))
    print(sum(ans))
    for i in range(len(ans)):
        if ans[i]==1:
            print("{} ".format(i+1), end="")

Submission status: Accepted

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

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

print(sum(b))
if len(ans) > 0:
    print(*ans)

Submission status: Accepted

Solution code:
#D問題
N = int(input())
A = list(map(int,input().split()))
C = [0 for i in range(N)]
for i in range(N):
    I = N-1-i
    n = N//(I+1)
    check = 0
    for j in range(n):
        check+=C[(I+1)*(j+1)-1]
    
    
    if A[I] == check%2:
        C[I] = 0
    else:
        C[I] = 1

b = 0
B = []
for i in range(N):
    if C[i] == 1:
        b+=1
        B.append(i+1)
print(b)
for i in range(b):
    print(B[i],end=" ")

Submission status: Accepted

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

A = [0] + A
for i in range(N//2, 0, -1):
    A[i] = sum(A[i::i])%2
ans = [i for i in range(N+1) if A[i]]
print(len(ans))
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int,input().split()))
I = N//2
import copy
b_list = copy.deepcopy(a_list)
for i in range(I-1,-1,-1):
#    print2(b_list,i)
    split = N//(i+1)
    wa = 0
    for s in range(split):
        wa += b_list[i+s*(i+1)]
    if wa % 2 != a_list[i]:
        b_list[i] = 1- a_list[i]
#print(b_list)
SUM = sum(b_list)
print(SUM)
if SUM != 0:
    
    for i in range(N):
        if b_list[i] == 1:
            print(i+1, end=" ")

Submission status: Accepted

Solution code:
import sys

M = int(input())

b_list = list(map(int, input().split()))
b_list.insert(0,0)
result_list = [0] * (M+1)

def getCount(index):
    multi = 2
    count = 0
    while True:
        next_index = index * multi
        if next_index > M:
            break
        count += result_list[next_index]
        multi += 1
    
    return count
        

for i in range(M, 0, -1):
    num = b_list[i]
    count = getCount(i)
    if count % 2 == num:
        result_list[i] = 0
    else:
        result_list[i] = 1

result_list.pop(0)
ans = ""
for i in range(len(result_list)):
    if result_list[i] == 1:
        ans += str(i+1) + " "

print(result_list.count(1))
if ans != "":
    print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_s = list(map(int, input().split()))
    results = [0]*n
    a_r = reversed(a_s)
    for i, a in enumerate(a_r):
        idx = (n-1) - i
        if sum(results[idx::(idx+1)]) % 2 != a:
            results[idx] = 1
    print(sum(results))
    idxs = [str(i+1) for i, r in enumerate(results) if r == 1]
    if results:
        print(' '.join(idxs))
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = [0] * (a + 1)
e = []
for i in range(len(b), 0, -1):
    d = 0
    for j in range(i, a + 1, i):
        d += c[j]
    if d % 2 != b[i-1]:
        c[i] += 1
        e.append(str(i))
f = sum(c)
print(f)
if len(e) > 1:
    print(" ".join(e))
elif len(e) == 1:
    print(e[0])

Submission status: Accepted

Solution code:
#abc134d

n=int(raw_input())
a=map(int,raw_input().split())
s=[]
x=[0]*n
for i in xrange(n,0,-1):
 y=0
 for j in xrange(i,n+1,i):
  y+=x[j-1]
 if y%2!=a[i-1]:
  x[i-1]=1
  s.append(i)
print len(s)
print ' '.join(map(str,s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[0]+[int(x) for x in input().split()]
b=[0]*(n+1)
 
for s in range(n,0,-1):
    i=s
    t=0
    while i<=n:
        t += b[i]
        i += s
    if a[s]!=t%2:
        b[s]=1
print(b.count(1))
for i in range(1,n+1):
    if b[i]==1:
        print(i)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
ans = []
for i in range(n, 0, -1):
    temp = sum(b[i - 1:n:i]) % 2
    if temp != a[i - 1]:
        b[i - 1] = 1
    if b[i - 1] == 1:
        ans.append(str(i))
print(len(ans))
if len(ans) > 0:
    print(" ".join(ans))

Submission status: Accepted

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


def returnResMod2(i):
    # i+1の倍数の箱のaiの和の剰余を求める
    res = sum([ansList[(i+1)*(k+1)-1] for k in range(N//(i+1))]) % 2
    return res


ansList = [0 for i in range(N)]
for i in range(N-1, -1, -1):
    tmp = (returnResMod2(i)+A[i]) % 2
    ansList[i] = tmp
    

M = sum(ansList)
print(M)
if M == 0:
    quit()
print(' '.join([str(i+1) for i, a in enumerate(ansList) if a == 1]))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ball = [0 for c in range(N)]
i = N
ballcount = 0
check = 2
out = 0
while i != 0 and out != N + 1:
    while check * i <= N: 
        ballcount += ball[check * i - 1]
        check += 1
    if ballcount % 2 != a[i - 1]:
        ball[i - 1] = 1
    check = 2
    i -= 1
    ballcount = 0
    out += 1
if out == N + 1:
    i = out
    print(-1)
M = 0
while i < N:
    if ball[i] == 1:
        M += 1
    i += 1
print(M)
i = 0
while i < N:
    if ball[i] == 1:
        print(i + 1)
    i += 1

Submission status: Accepted

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

bList=[0] * N

for i in reversed(range(N)):
    x = N // (i + 1)
    tmp = 0
    for j in range(1, x+1):
        tmp += bList[j * (i + 1) - 1]
    if aList[i] != tmp%2:
        bList[i] = 1
M = bList.count(1)

print(M)
if M != 0:
    for i in range(N):
        if bList[i] == 1:
            print(str(i+1), end = " ")

Submission status: Accepted

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

a_count = len(a_list)

boll_list = [0] * n

for rev_index, a in enumerate(reversed(a_list)):
    #indexはa_listへのアクセス用
    index = a_count - rev_index - 1
    divide_max = a_count // (index + 1)
    total = 0
    for divide in range(divide_max):
        total += boll_list[(index + 1) * (divide + 1) - 1]
    if a_list[index] != total % 2:
        boll_list[index] = 1

if 1 in boll_list:
    output_list = []
    for index, i in enumerate(boll_list):
        if i == 1:
            output_list.append(str(index + 1))
    print(len(output_list))
    print(' '.join(output_list))
else:
    print('0')

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = [0]*n
    for i in reversed(range(n)):
        x = n//(i+1)
        now = 0
        for j in range(1,x+1):
            now += b[j*(i+1)-1]
        if a[i] != now%2:
            b[i]=1
    m = b.count(1)
    print(m)
    if not m==0:
        for i in range(n):
            if b[i]==1:
                print(str(i+1),end=" ")
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
a_s = list(map(int,input().split()))
b_s = [0] * N
answers = []
for i,a in enumerate(list(reversed(a_s))):
    k = len(a_s)-i-1
    if sum(b_s[k::(k+1)])%2 != a_s[k]:
        b_s[k] = 1
        answers.append(str(k+1))
print(len(answers))
print(" ".join(list(reversed(answers))))

Submission status: Accepted

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

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

print(sum(res))
ans = []
for i, ele in enumerate(res):
    if ele == 1:
        ans.append(i)
print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
import math

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

for i in reversed(range(N)):
    x = math.floor(N/(i+1))
    temp = 0
    for k in range(1,x+1):
        temp += b[k*(i+1) - 1]
    if a[i] != (temp%2):
        b[i] = 1
M = b.count(1)
print(M)
if M != 0:
    for i in range(N):
        if b[i] ==1:
            print(str(i+1), end = " ")

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

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

b = [0] * N

for i, aa in enumerate(a):
    box_number = N-i
    sum_item_num = N//box_number
    item_sum = 0
    for sum_count in range(sum_item_num, 0, -1):
        if sum_count != 1:
            item_sum += b[(box_number * sum_count) - 1]
        else:
            # if 1
            b[box_number - 1] = aa ^ (item_sum % 2)

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = [0]*N
ct = 0
for i in reversed(range(N)):
    balls = sum(ans[2*i+1::i+1])
    if a[i] % 2:
        if balls % 2:
            pass
        else:
            ans[i] = 1
            ct += 1
    else:
        if balls % 2:
            ans[i] = 1
            ct += 1
        else:
            pass
print(ct)
for i in range(N):
    if ans[i]:
        print(i+1)

Submission status: Accepted

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

for s in range(n,0,-1):
  i=s
  t=0
  while i<=n:
    t += b[i]
    i += s
  if a[s]!=t%2:
    b[s]=1

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

Submission status: Accepted

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

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

for i, a in enumerate(A[::-1]):
    i = N - i
    v = B[i-1]
    for j in range(i*2, N+1, i):
        v ^= B[j-1]
    if v != a:
        B[i-1] ^= 1

M = len([b for b in B if b == 1])
print(M)
for i, b in enumerate(B):
    if b == 1:
        print(i+1)

Submission status: Accepted

Solution code:
from functools import reduce
from operator import xor


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


# 右の箱から順に詰める
dp = [0 for _ in range(N + 1)]
for i in range(N, 0, -1):
    dp[i] = reduce(
        xor,
        (dp[j] for j in range(2 * i, N + 1, i)),
        a[i - 1]
    )
b = [i for i in range(1, N + 1) if dp[i]]
ans = (
    '0' if len(b) == 0 else
    '{}\n{}'.format(
        len(b),
        ' '.join(map(str, b))
    )
)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = [0]*N
d = 1
r = []
for i in range(N, 0, -1):
  m = 0
  c = 2*i
  while c <= N:
    m += b[c-1]
    c += i
  if m % 2 != a[i-1]:
    b[i-1] = 1
    r.append(i)
print(sum(b))
print(" ".join([str(s) for s in r]))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(N)]
m = N // 2 + 1
for i in range(N,0,-1):
    if i >= m:
        b[i-1] = a[i-1]
    else:
        kaisu = N // i
        count = 0
        for j in range(2, kaisu+1):
            count += b[j*i-1]
        amari = count % 2
        if amari == 0 and a[i-1] == 1:
            b[i-1] = 1
        elif amari == 1 and a[i-1] == 0:
            b[i-1] = 1
print(sum(b))
for i in range(N):
    if b[i] == 1:
        print(i+1)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
num_l = [0]*N
bn = 0
for i in range(N, 0, -1):
    nn = 0
    for j in range(2*i, N+1, i):
        nn += num_l[j-1]

    if nn % 2 != A[i-1]:
        num_l[i-1] = 1

M = sum(num_l)
print(M)
if M != 0:
    ans = []
    flg = False
    for i, n in enumerate(num_l):
        if flg:
            print(' ', end='')
        if n == 1:
            print(i+1, end='')
        flg = True

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
 
b = [ 0 for _ in range(N)]
#M = 0
for i in reversed(range(1, N+1)):
    summ = 0
    for j in range(i, N+1, i):
        summ += b[j-1]
    if summ % 2 != a[i-1]:
    	b[i-1] = 1
    
 
cnt = sum(b)
print(cnt)
not_first = False
if cnt > 0:
 
    for j in range(N):
        if b[j] == 1:
            if not_first:
                print(" ", end="")
            print(j+1, end="")
            not_first = True
    print()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0 for i in range(n+1)]
a.reverse()
a.insert(0,0)
counter = 0
for i in range(1,n+1): #a[i]を見ている
    temp = 0
    t = 1
    while (n+1-i)*t <= n:
        temp += b[(n+1-i)*t]
        t += 1
    if temp%2 != a[i]:
        b[n+1-i] = 1
        counter += 1
print(counter)
for i in range(1,n+1):
    if b[i] == 1:
        if counter != 1:
            print(i,end= " ")
        else:
            print(i)
        counter -= 1

Submission status: Accepted

Solution code:
def solve(n, a):
    box = [0] * (n + 1)
    for i in reversed(range(1, n + 1)):
        j = 2
        count = 0
        while i * j < n + 1:
            if box[i * j] == 1:
                count += 1
            j += 1
        if a[i - 1] != count % 2:
            box[i] = 1
    ans = [str(i) for i, it in enumerate(box) if it == 1]
    return len(ans), ans


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    m, b = solve(N, A)
    print(m)
    if m > 0:
        print(' '.join(b))

Submission status: Accepted

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

    res = [0] * (N + 1)

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
M=0
b=[]
M=0
for i in range(N):
    b.append(0)
for j in range(N,0,-1):
    cnt=0
    for k in range(j,N+1,j):
        cnt+=b[k-1]
    if cnt%2!=a[j-1]:
        b[j-1]=1
        M+=1
c=[l+1 for l, x in enumerate(b) if x==1]
c=list(map(str,c))
print(M)
print(' '.join(c))

Submission status: Accepted

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

sum_index = [0]*(N+1)
index = []
for i in range(N)[::-1]:
    sum_ = 0
    for j in sum_index[i+1::i+1]:
        sum_ ^= j
    sum_index[i+1] = sum_ ^ A[i]
    if sum_index[i+1] == 1:
        index.append(str(i+1))

print(sum(sum_index))
if index:
    print(" ".join(index))