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:
# -*- coding utf-8 -*-
N = int(input())

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

bn = [0] * N

for i in range(N, 0, -1):
    s = sum(bn[(i - 1)::i]) % 2
    bn[i - 1] = 0 if s == an[i - 1] else 1

ans = sum(bn)
print(ans)
ans_b = []
if ans != 0:
    for i in range(N):
        if bn[i] == 1:
            ans_b.append(str(i + 1))
    print(' '.join(ans_b))

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
lst = list(map(int, input().split()))
slice_lst = lst[:int(N / 2)]
for i,k in enumerate(reversed(slice_lst)):
  sub_lst = lst[len(slice_lst)-i-1:len(lst):len(slice_lst)-i]
  if (k != sum(sub_lst) % 2):
    if (k == 0):
      lst[len(slice_lst)-i-1] = 1
    else:
      lst[len(slice_lst)-i-1] = 0

if (ans == -1):
  print(ans)
else:
  ans_lst = []
  for i,k in enumerate(lst):
    if (k == 1):
      ans_lst.append(str(i+1))
  print(len(ans_lst))
  result = ' '.join(ans_lst)
  print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
M = N//2
ans = -1

def fun(x):
    u = 0
    n = N//x-1
    for i in range(n):
        u+=a[x*(i+2)-1]
    return u%2

for i in range(M):
    y = fun(M-i)
    if a[M-i-1] == 1 and y == 1:
        a[M-i-1] = 0
    elif a[M-i-1] == 0 and y == 1:
        a[M-i-1] = 1

print(sum(a))
for j in range(N):
    if a[j] == 1:
        print(str(j+1)+" ", end="")

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:
def yakusuu(n):
    yakusuu_list = list()
    for i in range(n):
        if n % i == 0:
            yakusuu_list.append(i)
    return yakusuu_list


def baisuu(n, max_N):
    baisuu_list = list()
    for i in range(n, max_N + 1, n):
        baisuu_list.append(i)
    return baisuu_list


N = int(input())
A = [-1] + list(map(int, input().split()))
box = [0 for _ in range(N + 1)]
ans = list()

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

for i in range(N // 2, 0, -1):
    baisuu_list = baisuu(i, N)
    baisuu_xor = 0
    for b in baisuu_list:
        baisuu_xor ^= box[b]
    box[i] = baisuu_xor ^ A[i]

print(sum(box))
for i in range(1, N + 1):
    if box[i] == 1:
        ans.append(i)
print(" ".join(map(str, ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
1 2 3 4 5 6 ... N
任意のiについて
iの倍数が書かれた箱に入っているボールの個数の和を2で割ったあまりがai
"""

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

"""
1 2 3 4 5 6
0 1 0 1 0 1

i = 1  sum(As)%2 
i = 2  sum(As[::2]%2)

1    1 1 1 1 1 1 1 1 1 1
2    0 1 0 1 0 1 0 1 0 1
3    0 0 1 0 0 1 0 0 1 0
4    0 0 0 1 0 0 0 1 0 0
5    0 0 0 0 1 0 0 0 0 1
6    0 0 0 0 0 1 0 0 0 0
7    0 0 0 0 0 0 1 0 0 0
8    0 0 0 0 0 0 0 1 0 0 
9    0 0 0 0 0 0 0 0 1 0
10   0 0 0 0 0 0 0 0 0 1

後ろから決めていく？
"""
Bs = [0] * N
inball = []
for i in [N-i for i in range(N)]:
    n = N//i
    cnt = 0
    for j in [n-i for i in range(n)]:
        cnt += Bs[i*j-1]
    Bs[i-1] = (cnt+As[i-1]) % 2

ans = [i+1 for i,b in enumerate(Bs) if b==1]
M = len(ans)
print(M)
if M > 0:
    print(*ans)

Submission status: Accepted

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

ans=[]
li2=[0 for _ in range(n)]
for i in range(n,0,-1):
  count=0
  for j in range(i*2,n+1,i):
    if li2[j-1]==1:
      count+=1
  if count%2!=li[i-1]:
    li2[i-1]=1
    ans.append(i)

ans.reverse()
print(len(ans))
L=[str(a) for a in ans]
L=" ".join(L)
if len(L)!=0:
  print(L)

Submission status: Accepted

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

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

print(sum(B))
C = []
for k in range(N):
    if B[k] == 1:
        C.append(k+1)
print(*C)

Submission status: Accepted

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

h = N // 2 + N % 2
ans = [-1] * N

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

print(sum(ans))
for i, x in enumerate(ans):
    if x == 1:
        print(i+1)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split(' ')

b = [int(x) for x in a]

c = []
for i in range(n):
    c.append(0)

d=[]

for i in range(n):
    i = n - i
    s = 0
    for j in range(i*2,n+1,i):
     #   print(i,j)
        s = s + c[j-1]
    #print('i',i,'s',s,'b',b[i-1])
    if s%2 != b[i-1]:
        c[i-1] = 1
        d.append(i)

d=sorted(d)
print(len(d))
for i in range(len(d)):
    print(d[i],end=' ')

Submission status: Accepted

Solution code:
import heapq as hq
def main():
    n = int(input())
    a = list(map(int,input().split(' ')))
    ans = [0]*(n+1)
    ans_cnt = 0
    for num,i in enumerate(a[::-1]):
        cnt = 0
        for j in range(n-num,n+1,n-num):
            if ans[j] ==1:
                cnt += 1
        if cnt%2 != i:
            ans[n-num] = 1
            ans_cnt += 1
    print(ans_cnt)
    for num,i in enumerate(ans):
        if i:
            print(num,'',end='')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

boxin = []
bx = [0 for _ in range(N+1)]
for cnt in range(N, 0, -1):
    a = ax[cnt-1]
    i = 2
    memo_cnt = 0
    while 1:
        test_val = i * cnt
        if test_val > N:
            break
        if bx[test_val]:
            memo_cnt += 1
        i += 1
    if a != memo_cnt % 2:
        boxin.append(cnt)
        bx[cnt] = 1

 
box = len(boxin)
print(box)
if box != 0:
    boxin.reverse()
    print(' '.join(map(str, boxin)))

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int,input().split(' ')))
mid = N // 2
MAP = [0]*N
ans_l = []
for i in range(N-1,mid-1,-1):
    k = l[i]
    MAP[i] = k
    if k==1:
        ans_l.append(str(i+1))
flag = False
for i in range(mid,0,-1):
    s = N // i + 1
    t = 0
    for j in range(2,s):
        t += MAP[i*j-1]
    if t%2==0:
        if l[i-1]%2==1:
            ans_l.append(str(i))
            MAP[i-1] += 1
    else:
        if l[i-1]%2==0:
            ans_l.append(str(i))
            MAP[i-1] += 1
 
leng = len(ans_l)
print(leng)
print(" ".join(ans_l))

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int,input().split(' ')))
mid = N // 2
MAP = [0]*N
ans_l = []

for i in range(N,0,-1):
    s = N // i + 1
    t = 0
    for j in range(1,s):
        t += MAP[i*j-1]
    if t%2 != l[i-1]:
        ans_l.append(str(i))
        MAP[i-1] = 1
leng = len(ans_l)
print(leng)
print(" ".join(ans_l))

Submission status: Accepted

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

a.insert(0, 0)
b.insert(0, 0)

n = int(N/2)

for i in range(N, 0, -1):
    nums = 0
    for ii in range(2, int(N/i)+1):
        nums += b[i*ii]

    if nums % 2 != a[i]:
        b[i] += 1

sum_b = sum(b)
print(sum_b)

flag = False
for i, bb in enumerate(b):
    if i == 0:
        continue

    if bb != 0:
        flag = True
        print(i, end=' ')

if flag:
    print()

Submission status: Accepted

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

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    mod = [None] + read_h()

    i = n
    box = [None] * (n + 1)
    while i >= 1:
        s = sum(box[j] for j in range(i * 2, n + 1, i))
        box[i] = abs(mod[i] - (s % 2))
        i -= 1

    #  print([i for i in range(n + 1)])
    #  print(box)

    print(sum(box[1:]))
    t = [str(i) for i, b in enumerate(box) if b is not None and b > 0]
    if t:
        print(' '.join(t))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    al = list(map(int, input().split()))

    nums = [0] * n
    for i in range(n, 0, -1):
        if sum(nums[i-1::i]) % 2 != al[i-1]:
            nums[i-1] = 1

    print(sum(nums))
    print(*[i+1 for i, e in enumerate(nums) if e == 1])

Submission status: Accepted

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

def dq(N, Alist):
    Blist = [0]*(N//2+1)+Alist[N//2:]
    Alist = [0]+Alist
    for ind in range(N//2, 0, -1):
        total = 0
        for i in range(ind, N+1, ind):
            total += Blist[i]
        if total%2 != Alist[ind]:
                Blist[ind] = 1
    retnum = 0
    retind = []
    for ind, bi in enumerate(Blist):
        if bi == 1:
            retnum +=1
            retind.append(str(ind))
    print(retnum)
    if retnum > 0:
        print(" ".join(retind))
dq(N,Alist)

Submission status: Accepted

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

def index(n):
    return [i for i in range(2 * n, N + 1, n)]


F = set()
for n in range(N, 0, -1):
    a = sum([1 if i in F else 0 for i in index(n)])
    if a % 2 != A[n]:
        F.add(n)

print(len(F))
L = list(map(str, F))
print(" ".join(L))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
f = 0
for i in sorted(list(range(n)),reverse=True):
	k = n//(i+1)
	if a[i] == 1:
		if k == 1:
			b[i] = 1
		else:
			c = 0
			for j in range(0,k):
				c+=b[i+(j*(i+1))]
			if c % 2 == 0:
				b[i] = 1
	else:
		if k != 1:
			c = 0
			for j in range(0,k):
				c+=b[i+(j*(i+1))]
			if c % 2 == 1:
				b[i] = 1
print(sum(b))
result=[]
for i in range(len(b)):
	if b[i] == 1:
		result.append(i+1)
if len(result) > 0:
	print(*result)

Submission status: Accepted

Solution code:
def findcount(arr, x, n):
	ans = 0
	for i in range(x, n+1, x):
		ans += arr[i-1]
	# print(ans)
	return ans


n = int(input())
arr = [int(j) for j in input().split()]

ans = [False]*n
for i in range(n, 0, -1):
	x = findcount(ans, i, n)
	if x%2 == arr[i-1]:
		continue
	else:
		ans[i-1] = True

count = 0
temp = []
for x in range(1, n+1):
	if ans[x-1] == True:
		temp += [x]
		count += 1

print(count)
print(*temp)

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int,input().split(' ')))
mid = N // 2
MAP = [0]*N
ans_l = []

for i in range(N,0,-1):
    s = N // i + 1
    t = 0
    for j in range(1,s):
        t += MAP[i*j-1]
    if t%2 != l[i-1]:
        ans_l.append(str(i))
        MAP[i-1] = 1
leng = len(ans_l)
print(leng)
print(" ".join(ans_l))

Submission status: Accepted

Solution code:
import math
N = int(input())
ax = list(map(int,input().split()))

M = 0
boxin = []
bx = [0 for _ in range(N+1)]
for cnt in range(N, 0, -1):
    a = ax[cnt-1]
    tmp = 0
    for tmp_cnt in range(cnt*2, N+1, cnt):
        if bx[tmp_cnt] != 0:
            tmp += 1
    
    if tmp % 2 != a:
        bx[cnt] = 1
        boxin.append(cnt)

box = len(boxin)
print(box)
if box != 0:
    boxin.reverse()
    print(' '.join(map(str, boxin)))

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)

boxes = dict()
have_balls = list()
for bn in range(n, 0, -1):
    a = A[bn]
    s = 0
    for t in range(2, n+1):
        if bn * t > n:
            break
        s += boxes[bn*t]

    if s % 2 == a:
        boxes[bn] = 0
    else:
        boxes[bn] = 1
        have_balls.append(str(bn))

print(len(have_balls))
print(' '.join(have_balls))

Submission status: Accepted

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

for n in range(N):
    i = N - n
    BB = B[::i]
    if (sum(BB)) % 2 == A[i - 1]:
        B[i] = 0
    else:
        B[i] = 1
    if B[i] == 1:
        x.append(str(i))

if len(x) == 0:
    print(0)
else:
    print(len(x))
    print(' '.join(x))

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(i,n,i+1):
    if j==i:
      continue
    else:
      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())
listA=list(map(int,input().split()))
listB=[0 for i in range(N)]
listANS=[]
for i in range(N-1,-1,-1):
  listN=listA[i:N:i+1]
  if len(listN)==1 and listA[i]==1:
    listB[i]=1
  elif len(listN)>1 and listA[i]!=sum(listB[i:N:i+1])%2:
    listB[i]=1
for i in range(N):
  if listB[i]==1:
    listANS+=[i+1]
ANS=len(listANS)
print(ANS)
if ANS!=0:
  print(*listANS)

Submission status: Accepted

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

for n in range(N):
  i = N-n
  # print(i)
  BB = B[::i]
  if (sum(BB))%2 == A[i-1]:
    B[i] = 0
  else:
    B[i] = 1
    # print(B)
  if B[i] == 1:
    x.append(str(i))
  
if len(x) == 0:
  print(0)
else:
  print(len(x))
  print(' '.join(x))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 20 20:54:28 2019

@author: sp8783
"""
import copy

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

tmp = copy.deepcopy(lst)

f_lst = list(range(n//2))[::-1]

for i in f_lst:
    a = (sum(tmp[i::i+1])-tmp[i]) % 2
    b = tmp[i]
    if a == b:
        tmp[i] = 0
    else:
        tmp[i] = 1
    
print(sum(tmp))
x = [i+1 for i, x in enumerate(tmp) if x == 1]
print(*x)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [0] + list(map(int, input().split()))
b = [0 for i in range(n + 1)]

for i in range(n, 0, -1):
    if i > n // 2:
        b[i] = a[i]
    else:
        s = 0
        for j in range(2, n // i + 1):
            if i * j > n:
                break
            s += b[i * j]
        mod = s % 2
        if mod == 0:
            b[i] = a[i]
        else:
            b[i] = 1 - a[i]

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

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))


def func(n):
    # print(n)
    tmp = n + n
    a = 0
    while tmp <= N:
        a += ans[tmp - 1]
        tmp += n
    return a % 2


N = int(input())
A = inpl()
ans = [0 for i in range(N)]

for i in reversed(range(N)):
    if func(i + 1) != A[i]:
        ans[i] = 1

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

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

Submission status: Accepted

Solution code:
import math

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

use=[-1 for _ in range(N)]
for i in reversed(range(N)):
    use[i]=a[i]
    #print(i,use)
    if i+1==N//2+1:
        break
#print('half')
for i in reversed(range(N//2)):
    x=i+1
    tmp=0
    cnt=2
    while cnt*x<=N:
        tmp+=use[cnt*x-1]
        #print(x,cnt,tmp)
        cnt+=1
    use[i]=(tmp+a[i])%2
    #print(use)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
ans=[]
cnt=0
B = [0 for i in range(N)]
import math
for i in range(math.floor(N/2),N):
    B[i]=A[i]
    if(A[i]==1):
        cnt+=1
        ans.append(i+1)
        
from functools import reduce
for i in range(math.floor(N/2)-1,-1,-1):
    R=[B[(i+1)*j-1] for j in range(2,(N//(i+1))+1)]
    r=sum(R)%2
    l = int(not (r)) if A[i]==1 else int(r)
    B[i]=l
    if l==1:
        cnt+=1
        ans.append(i+1)
print(cnt)
if cnt>0:
    print(" ".join(map(str, ans)))

Submission status: Accepted

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

ball_list = [0] * (N + 1)
for n in reversed(range(1, N + 1)):
    mod = 0
    for i in range(n, N + 1, n):
        mod ^= ball_list[i]
    if mod != a_list[n - 1]:
        ball_list[n] = 1

num = sum(ball_list)
print(num)

if num > 0:
    for i, b in enumerate(ball_list):
        if b == 1:
            print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


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

    return divisors


def main():
    N = int(input())
    # A = [
    #     int(input())
    #     for _ in range(N)
    # ]
    A = [int(a) for a in input().split()]

    res1 = []
    bucket = [0] * (N + 1)

    i = N
    for Ai in reversed(A):
        i -= 1
        k = i + 1
        if k * 2 > N:
            if Ai == 1:
                res1.append(k)
                bucket[k] = 1

            continue
        if k == 1:
            if len(res1) % 2 != Ai:
                res1.append(k)
            break

        s = 0
        j = 0
        while True:
            j+=1
            if j * k > N:
                break
            s += bucket[j * k]

        if s % 2 != Ai:
            res1.append(k)
            bucket[k] = 1
    print(len(res1))
    print(*res1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

def main():
    n = int(input())
    a = np.zeros([n], dtype=int)
    # box = np.array(range(1,n+1))
    a = list(map(int, input().split(" ")))
    b = np.zeros_like(a)

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

    for i in range(1,n//2+1)[::-1]:
        if np.sum(b[i-1::i])%2 != a[i-1]:
            b[i-1] = 1

    ball = np.where(b==1)[0]
    print(len(ball))
    for i in ball:
        print(i+1, end=" ")
        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i in reversed(range(1, n+1)):
    if i * 2 > n:
        b[i-1] = a[i-1]
    else:
        if sum(b[i-1::i]) % 2 != a[i-1]:
            b[i-1] = 1
l = []
for i in range(n):
    if b[i] == 1:
        l.append(i+1)
print(len(l))
if len(l) > 0:
    print(' '.join(list(map(str, l))))

Submission status: Accepted

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

for i in range(1,N+1)[::-1]:
    tmp = 0
    for j in range(1,N//i+1):
        tmp = (tmp + X[i*j]) % 2
    X[i] = tmp ^ A[i]
print(sum(X))
[print(i) for i, a in enumerate(X) if a]

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    results = [0]*n
    for i, a in enumerate(reversed(a_s)):
        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:
import sys


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

    M = set()
    lenA = len(A)
    for i in range(len(A))[::-1]:
        if i > lenA/2:
            if A[i] == 1:
                M.add(i+1)
        else:
            bai = set([x*(i+1) for x in range(1, int(lenA/(i+1))+1)])
            num = len(M&bai) % 2
            if A[i] != num:
                M.add(i+1)
    
    print(len(M))
    if len(M) > 0:
        print(*M)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=[-1]*n
for i in range(n-1,-1,-1):
    if i>=(n+1)/2:
        x[i]=a[i]
    else:
        j=(i+1)*2
        while(j<=n): 
            a[i]=(a[i]+a[j-1])%2
            j+=i+1
        x[i]=a[i]
print(sum(x))
if sum(x)!=0:
    for i in range(n):
        if x[i]==1:
            print(i+1,end=' ')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = a[i - 1] ^ 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:
n = int(input())
A = [int(s) for s in input().split()]
cen = n //2
ANS = [0]*(cen)
A_p = A[cen:n]
ANS = ANS + A_p

for i in range(cen):
    part_sum = sum(ANS[cen-i-1::cen-i])
    dot = part_sum % 2
    if dot == A[cen-i-1]:
        pass
    else:
        ANS[cen-i-1] = 1

sum_ans = sum(ANS)
print(sum_ans)
if sum_ans == 0:
    pass
else:
    B = []
    for i in range(n):
        if ANS[i] != 0:
            B.append(i+1)
        else:
            pass
    BB = [str(a) for a in B]
    BB =" ".join(BB)
    print(BB)

Submission status: Accepted

Solution code:
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


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


test_str = '''
4
1 0 1 0
'''
#
# 1 1 1

def MAIN():
  # T_IN()
  A()


def A():
  n = IN_I()
  li = IN_L_I()

  tmp = [False] * n
  tmp2 = [False] * n
  for i, b in enumerate(reversed(li)):
    ci = n - i - 1
    # print("hoge:",i,b,ci)
    if b == 1 and not tmp[ci]:
      tmp[ci] = True
      tmp2[ci] = True

    if b == 0 and tmp[ci]:
      tmp[ci] = False
      tmp2[ci] = True

    if tmp2[ci]:
      # print(ci, " || ",make_divisors(ci + 1))
      for j in make_divisors(ci + 1):
        if j != ci + 1:
          tmp[j - 1] = not tmp[j - 1]

    # print(tmp)
    # print(tmp2)

  puts = [i for i, x in enumerate(tmp2) if x]
  print(len(puts))
  if len(puts) > 0:
    print(" ".join([str(i + 1) for i in puts]))
  return None


def B():
  return None


def C():
  return None


MAIN()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
c = 0
d = [0] * n
ans = []
for i in range(n):
    m = n-i
    p = 1
    b = 0
    while m * p <= n:
        tmp = m * p
        if d[tmp-1] == 1:
            b += 1
        p += 1
    if b % 2 != a[m-1]:
        d[m-1] = 1
        ans.append(m)
        c += 1

if c%2 != a[0]:
    print('-1')
else:
    print(c)
    print(" ".join(repr(e) for e in ans))

Submission status: Accepted

Solution code:
N = int(input())
A = map(int, raw_input().split())
ANS = set()

for j in range(N, 0, -1):
    s = 0
    for k in range(j+j, N+1, j):
        if k in ANS:
            s += 1

    am = s % 2
    if A[j-1] != am:
        ANS.add(j)

print(len(ANS))
str_ANS = [str(j) for j in ANS]
print(" ".join(str_ANS))

Submission status: Accepted

Solution code:
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
import copy
def divisor(n): #約数
    f=[]
    d=[1]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    for i in range(len(f)):
        t=[]
        for j in range(1,f[i][1]+1):
            t.append(f[i][0]**j)
        for j in range(len(d)):
            for k in range(len(t)):
                d.append(d[j]*t[k])
    return sorted(d)
n=I()
A=IL()
Ans=copy.deepcopy(A)
AA=[0]*n
AAA=[0]*n
last=-1
first=n
ans=0
c=True
while first>0:
    last=first
    first=first//2
    for i in range(first,last):
        if A[i]==1:
            if AA[i]==1:
                c=False
                break
            AA[i]=1
            L=divisor(i+1)
            for l in L:
                if A[l-1]==0:
                    A[l-1]=1
                else:
                    A[l-1]=0
                    
                if AAA[l-1]==0:
                    AAA[l-1]=1
                else:
                    AAA[l-1]=0   
                

if AAA!=Ans or not c:
    print(-1)
    print(A)
else:
    print(sum(AA))
    for i in range(n):
        if AA[i]==1:
            print(i+1,end=" ")
    print()

Submission status: Accepted

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

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    mod = [None] + read_h()

    i = n
    box = [None] * (n + 1)
    while i >= 1:
        if n // i <= 1:
            box[i] = mod[i]
            i -= 1
            continue

        s = sum(box[j] for j in range(i * 2, n + 1, i))
        box[i] = abs(mod[i] - (s % 2))

        i -= 1

    #  print([i for i in range(n + 1)])
    #  print(box)
    print(sum(box[1:]))
    t = [str(i) for i, b in enumerate(box) if b is not None and b > 0]
    if len(t) > 0:
        print(' '.join(t))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# D
N = int(input())

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

X=[0]*N
for i in range(N, 0, -1):
    j=1
    tmp=0
    while(i*j<=N):
        tmp+=X[i*j-1]
        j+=1
    if tmp%2 == a[i-1]:
        X[i-1]=0
    else:
        X[i-1]=1
#     X[i-1] = tmp%2

# if (sum(X[1:])%2==a[0]):
#     X[0] = 0
# else:
#     X[0] = 1
    
print(sum(X))
for i, j in enumerate(X):
    if j == 1:
        print(str(i+1) + " ", end="")

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


n = int(input())
a = list(map(int, input().split()))
box = [0 for _ in range(n)]
sum_box = [0 for _ in range(n)]
for i in range(n)[::-1]:
    if a[i] == 1 and sum_box[i] % 2 == 0:
        for k in make_divisors(i+1):
            sum_box[k-1] += 1
        box[i] = 1
    elif a[i] == 1 and sum_box[i] % 2 != 0:
        box[i] = 0
    elif a[i] != 1 and sum_box[i] % 2 != 0:
        for k in make_divisors(i+1):
            sum_box[k-1] += 1
        box[i] = 1
    elif a[i] != 1 and sum_box[i] % 2 == 0:
        box[i] = 0
ans = []
for i, b in enumerate(box):
    if b == 1:
        ans.append(str(i+1))
if not ans:
    print(0)
else:
    s = ' '.join(ans)
    print(len(ans))
    print(s)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(1,n // 2 + 1):
    an = a[n //2 - i]
    if (sum(a[n // 2 - i::n // 2 + 1 - i]) - an) % 2 == an:
        a[n // 2 - i] = 0
    else:
        a[n // 2 - i] = 1
b = []
cnt = 0
for i in range(len(a)):
    if a[i] == 1:
        b.append(str(i + 1))
        cnt += 1
if cnt != 0:
    print(cnt)
    print(' '.join(b))
else:
    print(0)

Submission status: Accepted

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

balls = [0] * n
nrev = reversed(range(n))
ballcount = 0

for i in nrev:
    if i > n // 2:
        balls[i] = a[i]
        if balls[i] == 1:
            ballcount = ballcount + 1
    else:
        kosuu = n // (i + 1)
        ball = 0
        now = i + 1
        for j in range(kosuu):
            if balls[now - 1] == 1:
                ball = ball + 1
            now = now + i + 1
        if ball % 2 == a[i]:
            balls[i] = 0
        else:
            balls[i] = 1
            ballcount = ballcount + 1

print(ballcount)

for i in range(n):
    if balls[i] == 1:
        print(i + 1)

Submission status: Accepted

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

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

for i in reversed(range(1,int(n/2)+1)):
    c=0
    if a[i]==0:
        for j in range(2*i,n+1,i):
            if b[j]==1:
                c=c+1
        if c % 2 ==0:
            b[i]=0
        else:
            b[i]=1
    if a[i]==1:
        for j in range(2*i,n+1,i):
            if b[j]==1:
                c=c+1
        if c % 2 ==0:
            b[i]=1
        else:
            b[i]=0

cx=0
for i in range(1,n+1):
    if b[i]==1:
        cx=cx+1

if any(b)==False:
    print(0)
else:
    def func1(lst, value):
        return [i for i, x in enumerate(lst) if x == value]
    idx=func1(b,1)
    print(cx)
    print(' '.join(map(str, idx)))