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

# Nの倍数の数を格納する辞書
baisuu = {i:0 for i in range(1,N+1)}
M=0
out_list=[]

half=N//2

for i,ai in enumerate(a):
    now_index=N-i
    if now_index > half:
        if ai==1:
            soinsuu = make_divisors(now_index)
            out_list.append(now_index)
            M+=1
            for so in soinsuu:
                baisuu[so]+=1
    else:
        if baisuu[now_index]%2!=ai:
            out_list.append(now_index)
            M+=1
            soinsuu = make_divisors(now_index)
            for so in soinsuu:
                baisuu[so]+=1

print(M)
if M>0:
    out_list=sorted(out_list)
    print(" ".join(list(map(str, out_list))))

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = list(map(int, input().split()))
    count = [0]*N
    answer=[]
    M = 0
    for i in range(N)[::-1]:
        j = i+1
        if count[i]%2 != A[i]:
            answer.append(j)
            M += 1
            div = make_divisors(j)
            for k in div:
                count[k-1] += 1
    print(M)
    print(*answer)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

b=[]
M = 0
count = [0 for _ in range(N+1)]
for i in reversed(range(1,N+1)):
    if count[i]%2 == a[i-1]: continue
    else:
        for j in range(1,int(i**0.5)+1):
            if i%j==0:
                count[j]+=1
                if j!=i//j:
                    count[i//j]+=1
        M+=1
        b.append(i)
print(M)
if M!=0:
    print(*b)

Submission status: Accepted

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

b = []
c = [0]*len(a)
for i in range(N,0,-1):
  total = 0
  for m in range(i+i,N+1,i):
    total += c[m]
  if total%2!=a[i]:
    c[i] = 1
    b.append(i)

print(len(b))
for bm in b:
  print('{} '.format(bm))

Submission status: Accepted

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

b = []
c = [0]*(N+1)
for i in range(N,0,-1):
  #print('  a[{}]={}'.format(n,a[n-1]))
  total = 0
  for m in range(i+i,N+1,i):
    total += c[m]
  if total%2!=a[i]:
    c[i] += 1
    b.append(i)

print(len(b))
for bm in b:
  print('{} '.format(bm))

Submission status: Accepted

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

B = [0] * N # どの箱にボールを入れたかのリスト（0,1のみ入る）
ans = [] # ボールを入れた箱のインデックスを格納するリスト

for n in range(N-1,-1,-1): # 箱は、後ろから見ていく
  num = 0 # その箱の倍数の箱に入っているボールの合計数
  
  # その箱の倍数の箱に入っているボールの個数を計上
  for j in range(2*(n+1), N+1 , n+1): 
    num += B[j-1]
    
  # 合計数がAと一致していない場合
  if num % 2 != A[n]:
    B[n] = 1
    ans.append(n+1)

count = len(ans)
print(count)
if count > 0:
    print(' '.join(map(str, ans)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

b = [0] * (n+1)
for i in reversed(range(1, n+1)):
    bi = 0
    for j in range(2, n//i + 1):
        bi += b[i*j]
    bi %= 2

    if bi != a[i-1]:
        b[i] = 1
    else:
        b[i] = 0

b_idx = [str(i) for i in range(1, n+1) if b[i] == 1]
m = len(b_idx)
print(m)
if m > 0:
    print(' '.join(b_idx))

Submission status: Accepted

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

b = [0] * (n+1)
for i in reversed(range(1, n+1)):
    bi = 0
    for j in range(2, n//i + 1):
        bi += b[i*j]
    bi %= 2

    if bi != a[i]:
        b[i] = 1
    else:
        b[i] = 0

b_idx = [str(i) for i in range(1, n+1) if b[i] == 1]
m = len(b_idx)
print(m)
if m > 0:
    print(' '.join(b_idx))

Submission status: Accepted

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

b = [0] * (n+1)
for i in reversed(range(1, n+1)):
    bi = 0
    for j in range(2, n//i + 1):
        bi += b[i*j]
    bi %= 2

    if bi != a[i]:
        b[i] = 1
    else:
        b[i] = 0



m = sum(b[1:])
print(m)
if m > 0:
    b_idx = [str(i) for i in range(1, n+1) if b[i] == 1]
    print(' '.join(b_idx))

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)[::-1]:
    tmp = i+1
    pl = a[i]
    tmp += i+1
    while tmp <= n:
        pl += b[tmp-1]
        tmp += i+1
    b[i] = pl % 2
for i in range(n):
    if b[i] == 1:
        ans.append(i+1)
print(len(ans))
print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
An = input().split(' ')
ball_list = [0] * N
output_list = []
count = 0
for i in range(N):
    sum_amari = sum(ball_list[(N - i -1)::(N - i)])
    if sum_amari % 2 != int(An[N - i -1]): 
        ball_list[N - i -1] = 1
        output_list.append(str(N - i))
output_list.reverse()
print(len(output_list))
if len(output_list) > 0:
    print(' '.join(output_list))

Submission status: Accepted

Solution code:
def main(A,N):
    A = [0] + A
    for a in range(N//2,0,-1):
        #print(inds[ind::ind+1])
        if sum(A[a::a]) %2== 0:
            A[a] = 0
        else:
            A[a] = 1
        
    res = [x for x in range(0,N+1) if A[x]]
    print(len(res))
    print(*res)

N = int(input())
A = [int(x) for x in input().split()]
    
main(A,N)

Submission status: Accepted

Solution code:
def main(A,N):
    A = [0] + A
    for a in range(N-1,0,-1):
        #print(inds[ind::ind+1])
        if sum(A[a::a]) %2== 0:
            A[a] = 0
        else:
            A[a] = 1
        
    res = [x for x in range(0,N+1) if A[x]]
    print(len(res))
    print(*res)

N = int(input())
A = [int(x) for x in input().split()]
    
main(A,N)

Submission status: Accepted

Solution code:
#43 ABC134D
n=int(input())
a=list(map(int,input().split()))
x=[0 for _ in range(n)]
for i in range(n,0,-1):
	x[i-1]=1 if a[i-1]!=sum([x[j] for j in range(i-1,n,i)])%2 else 0
#print(x)
j=True
for i in range(n):
	if a[i]!=sum([x[j] for j in range(i,n,i+1)])%2:
		j=False
if j:
	print(sum(x))
	if sum(x)!=0:
		res=[]
		for i,t in enumerate(x):
			if t==1:
				res.append(str(i+1))
		print(" ".join(res))
else:
	print(-1)

Submission status: Accepted

Solution code:
import math
N=int(input())
A = list(map(int,input().split()))
s = [0]*N
ans=0

for i in reversed(range(N)):
    floor = math.floor(N/(i+1))
    sum=0
    for k in range(1,floor+1):

        sum+=s[((i+1)*k)-1]
    if (sum - A[i])%2 == 1:
        s[i] = 1
        ans+=1

print(ans)
for i in range(N):
    if s[i] == 1:
        print(i+1)

Submission status: Accepted

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

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

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

print(len(ans))
if ans:
    print(' '.join(ans))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = tuple(map(int,input().split()))
b = [0] * n
for i in range(n,0,-1):
  c = 0
  for j in range(i,(n//i+1)*i,i):
    c += b[j-1]
  if c % 2 == a[i-1]:
    continue
  else:
    b[i-1] = 1
d = []
for i in range(n):
  if b[i] == 1:
    d.append(i+1)
print(len(d))
print(' '.join(map(str,d)))

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())
A = list(map(int, input().split()))
ans = deque([])
num = deque([])

def make_divisors(t):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if t % i == 0:
            divisors.add(i)
            if i != t // i:
                divisors.add(t//i)

    # divisors.sort()
    return divisors


for i in range(n-1, -1, -1):
    if A[i] == 0:
        continue
    else:
        ans.appendleft(i+1)
        check = make_divisors(i+1)
        for j in check:
            A[j-1] = not A[j-1]

print(len(ans))
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import glob
import numpy as np


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\134\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class D(Common):

    def resolve(self):

        box_num = int(self.input_data())
        remain = [int(i) for i in self.input_data().split()]

        boxes = [0 for i in range(box_num)]
        ball_num = 0

        for box in range(box_num, 0, -1):
            ball_num = 0
            for j in range(box-1, box_num, box):
                ball_num += boxes[j]
            if ball_num % 2 != remain[box-1]:
                boxes[box-1] = 1
                ball_num += 1

        print(str(ball_num))
        for i in range(box_num):
            if boxes[i] == 1:
                print(str(i+1), end=" ")


solver = D(REL_PATH)
solver.exec_resolve()

Submission status: Accepted

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

put = [0] * n

for i in reversed(range(n)):
    if sum(put[i::i+1])%2 != lst[i]:
        put[i] = 1

print(sum(put))
for index,i in enumerate(put):
    if i==1:
        print(index+1)

Submission status: Accepted

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


def get_divisors(n, reverse=False):
    from math import sqrt
    divisors = []
    for num in range(1, int(sqrt(n))+1):
        if n % num == 0:
            divisors.append(num)
            if n//num != num:
                divisors.append(n//num)
    return sorted(divisors, reverse=reverse)

status = [0] * N
answers = []
for i in range(N, 0, -1):
    if A[i-1] == status[i-1]:
        continue
    answers.append(i)
    divisors = get_divisors(i)
    a = A[i-1]
    for divisor in divisors:
        status[divisor-1] = (1 + status[divisor-1]) % 2

print(len(answers))
for ans in answers:
    print(ans, end=" ")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [0 for i in range(N)]
for n in range(N):
    step = N - n
    sm = A[step-1]
    for i in range(step-1, N ,step)[::-1]:
        sm += B[i]
    B[step-1] = (sm%2)
    #print (B)
print (sum(B))
C = " ".join([str(i+1) for i in range(len(B)) if B[i]])
print (C)

Submission status: Accepted

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

Submission status: Accepted

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

r=[0]*n

for i in range(n)[::-1]:
    if sum(r[i::i+1])%2 != a[i]:
        r[i]=1

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

Submission status: Accepted

Solution code:
#coding utf-8
N=int(input())
a=list(map(int,input().split())) 
a=[0]+a
b=[0 for i in range(N+1)]
for i in range(N,0,-1):
  y=2
  tmp=0
  x=i*y
  while x<N+1:
    tmp+=b[x]
    y +=1
    x=i*y
  if tmp%2!=a[i]:
    b[i]=1
    
print(b.count(1))
indexes = [i for i,x in enumerate(b) if x==1]
indexes = map(str,indexes)
if b.count(1)!=0:
  print(' '.join(indexes))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#######################################
import numpy as np
#######################################
n = int(input())
a = list(map(int, input().split()))
ret = np.zeros(n+1, dtype="int")
ret2 = []

for i in reversed(list(range(n))): 
  if sum(ret[::i+1][1:])%2 != a[i]:
    ret[i+1] = 1
    ret2.append(i+1)

print(sum(ret[1:]))
print(" ".join(list(map(str, ret2[::-1]))))

Submission status: Accepted

Solution code:
#######################################
import numpy as np
#######################################
n = int(input())
a = np.array(list(map(int, input().split())))
ret = [0]*(n+1)
ret2 = []

for i in reversed(list(range(n))): 
  if sum(ret[::i+1][1:])%2 != a[i]:
    ret[i+1] = 1
    ret2.append(i+1)

print(sum(ret[1:]))
print(" ".join(list(map(str, ret2[::-1]))))

Submission status: Accepted

Solution code:
import numpy as np

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

for i in reversed(list(range(n))): 
  if sum(ret[::i+1][1:])%2 != a[i]:
    ret[i+1] = 1
    ret2.append(i+1)

print(sum(ret[1:]))
print(" ".join(list(map(str, ret2[::-1]))))

Submission status: Accepted

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

for i in reversed(list(range(n))): 
  if sum(ret[::i+1][1:])%2 != a[i]:
    ret[i+1] = 1
    ret2.append(i+1)

print(sum(ret[1:]))
print(" ".join(list(map(str, ret2[::-1]))))

Submission status: Accepted

Solution code:
#######################################
import numpy as np
#######################################
n = int(input())
a = np.array(list(map(int, input().split())))
ret = np.zeros(n+1, dtype="int")
tmp = list(range(n+1))
ret2 = []

for i in reversed(list(range(n))): 
  if sum(ret[::i+1][1:])%2 != a[i]:
    ret[i+1] = 1
    ret2.append(i+1)

print(sum(ret[1:]))
print(" ".join(list(map(str, ret2[::-1]))))

Submission status: Accepted

Solution code:
#######################################
import numpy as np
#######################################
n = int(input())
a = np.array(list(map(int, input().split())))
ret = np.zeros(n+1, dtype="int")
tmp = list(range(n+1))
ret2 = []

for i in reversed(list(range(n))): 
  if sum(ret[::i+1][1:])%2 != a[i]:
    ret[i+1] = 1
    ret2.append(i+1)

print(sum(ret[1:]))
ret2 = sorted(ret2)
print(" ".join(list(map(str, ret2))))

Submission status: Accepted

Solution code:
#######################################
import numpy as np

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))
#######################################
n = int(input())
a = np.array(list(map(int, input().split())))
ret = np.zeros(n+1, dtype="int")
tmp = list(range(n+1))
ret2 = []

for i in reversed(list(range(n))): 
  if sum(ret[::i+1][1:])%2 != a[i]:
    ret[i+1] = 1
    ret2.append(i+1)

print(sum(ret[1:]))
ret2 = sorted(ret2)
cout(ret2)

Submission status: Accepted

Solution code:
from collections import OrderedDict
N = int(input())
a = list(map(int, str(input()).split()))

box = OrderedDict(zip(range(N, 0, -1), [0] * N))
output = list()
count = 0
for i in box:
    mul = N // i
    total_ball = 0
    for m in range(1,mul+1):
        total_ball += box[m * i]
    if (a[i-1] == 1 and total_ball % 2 == 0) or (a[i-1] == 0 and total_ball % 2 == 1) :
        box[i] = 1
        count += 1
        output.append(str(i))
    else:
        pass

if len(output) != 0:
    print(count)
    print(' '.join(output))
else:
    print(0)

Submission status: Accepted

Solution code:
def main(n, a):
    box = [0] * n
    for i in range(n, 0, -1):
        if a[i - 1] != sum(box[i - 1 :: i]) % 2:
            box[i - 1] = 1

    box_indices = [i + 1 for i in range(n) if box[i] == 1]
    print(sum(box))
    print(*box_indices)


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

Submission status: Accepted

Solution code:
n = int(input())
moto = [int(i) for i in input().split()]
 
array=[0]*n
 
for i in reversed(range(1,n+1)):
  if sum(array[i-1::i])%2 != moto[i-1]:
    array[i-1] = 1
    
m = array.count(1)
print(m)
ans = ""
for i in range(n):
  if array[i] == 1:
    print(i+1, end=" ")

Submission status: Accepted

Solution code:
n = int(input())
moto = [int(i) for i in input().split()]
 
array=[0]*n
 
for i in reversed(range(1,n+1)):
  if sum(array[i-1::i])%2 != moto[i-1]:
    array[i-1] = 1
    
m = sum(array)
print(m)
ans = ""
for i in range(n):
  if array[i] == 1:
    print(i+1, end=" ")

Submission status: Accepted

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

def zero_or_one(i):
	count = 0
	num = i+1
	while num <= N:
		count += box[num-1]
		num += i+1
	if count%2 == a[i]:
		box[i] = 0
	else:
		box[i] = 1

for i in reversed(range(N)):
	zero_or_one(i)

ball = 0
ans = []
for i in range(N):
	if box[i] == 1:
		ball += 1
		ans.append(i+1)

if ball == 0:
	print(0)
else:
	print(ball)
	ans = " ".join(map(str,ans))
	print(ans)

Submission status: Accepted

Solution code:
def D_PreparingBoxes():
    N = int(input())
    a = list(map(int, input().split()))
    b = [0] * N
    for x in reversed(range(N)):
        if sum(b[x::x+1]) % 2 != a[x]:
            b[x] = 1
    print(sum(b))
    for x in range(N):
        if b[x]:
            print(x+1, end=" ")

if __name__ == "__main__":
    D_PreparingBoxes()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
box = [0] * n
ansli = []
ans = 0
for i in reversed(range(n)):
  if sum(box[i::i+1]) % 2 != a[i]:
    box[i] = not box[i]
    ansli.append(str(i+1))
    ans += 1
print(ans)
print(' '.join(ansli))

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + [int(s) for s in input().split()]
ball = [0] * (N + 1)
for i in range(N, 0, -1):
    ball[i] = (sum(ball[i::i]) - A[i]) % 2
ans = [i for i, v in enumerate(ball) if v == 1]
print(len(ans))
print(*ans)

Submission status: Accepted

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

    for i in reversed(range(1, N + 1)):
        target = N // i
        v = sum([B[i * j - 1] for j in range(1, target + 1)])
        if v % 2 != A[i - 1]:
            B[i - 1] = 1
            ans.append(i)

    print(len(ans))
    if ans:
        print(" ".join(map(str, ans)))


if __name__ == '__main__':
    p_d()

Submission status: Accepted

Solution code:
def multiple_factors(i, N):
  factors = []
  for index in range(0, N//i):
    factors.append(int((index+1)*i))
  return factors
  
def assign_ball(factors, blist, ai, b_add_index):
  sum_b = 0
  for index in range(len(factors)-1, 0, -1):
    sum_b += blist[factors[index]-1]
  
  if ai != sum_b%2:
    blist[factors[0]-1] = 1
    b_add_index.append(str(factors[0]))
  return blist, b_add_index

      
N = int(input())
alist = list(map(int, input().split()))
blist = [0 for i in range(N)]
b_add_index = []
for i in range(N-1,-1, -1):
  factors = multiple_factors(i+1, N)
  blist, b_add_index = assign_ball(factors, blist, alist[i], b_add_index)

if sum(blist)%2 != alist[0]:
  print(-1)
else:
  print(len(b_add_index))
  print(" ".join(b_add_index))

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# from other person's code
n = int(input())
a = list(map(int, input().split()))
ls = [0]*(n+1)
ans = []
for i in reversed(list(range(n))):
    if sum(ls[::i+1][1:]) % 2 != a[i]:
        ls[i+1] = 1
        ans.append(i+1)
print(sum(ls))
if ans: print(' '.join(map(str, ans)))

Submission status: Accepted

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

Submission status: Accepted

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

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):
    mod = sum(b[i::i]) % 2
    if mod == a[i]:
        pass
    else:
        b[i] = 1
    
print(b.count(1))
for idx, n in enumerate(b):
    if n:
        print(idx, '', end='')

Submission status: Accepted

Solution code:
n = int(input())
#a1~an
l = list(map(int, input().split()))
box = [0]*n
num_box = list(range(1,n+1))
x = list(reversed(range(n)))
for i in x:
    if l[i] == 1 and sum(box[i::num_box[i]])%2==0:
        box[i] += 1
    elif l[i] == 1 and sum(box[i::num_box[i]])%2==1:
        continue
    elif l[i] == 0 and sum(box[i::num_box[i]])%2==0:
        continue
    elif l[i] == 0 and sum(box[i::num_box[i]])%2==1:
        box[i] += 1

num_lis = [str(i) for i in num_box if box[i-1] == 1]
print(len(num_lis))
print(' '.join(num_lis))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
boxes = [0 for _ in range(N)]
ans = []
for i in range(N):
    j = N-i
    count = sum([boxes[k] for k in range(j-1,N,j)])
#    k = j*2
#    while k<N+1:
#        if k in ans:
#            count += 1
#        k += j
    if count%2 != a[j-1]:
        ans.append(j)
        boxes[j-1] = 1
print(len(ans))
ans = [str(x) for x in ans]
ans = ' '.join(ans)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
# /usr/bin/python3

def main():
  N = int(input())
  liA = list(map(int, input().strip().split(' ')))
  boxes = [0 for _ in range(len(liA))]
  index = []
  for i in range(len(liA))[::-1]:
    sumBoxes = sum([boxes[j] for j in range(i, len(boxes), i+1)])
    if sumBoxes % 2 != liA[i]:
      boxes[i] += 1
      index += [i+1]
  print(len(index))
  print(' '.join(map(str, index)))
  pass

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
b = [0]*N
c = []
m = 0

for i in range(N-1,N//2,-1):
  if a[i] == 1:
    b[i] = 1
    c.append(i+1)
    m += 1
for i in range(N//2,-1,-1):
  sum_b = 0
  j = (i+1)*2
  while j <= N:
    sum_b += b[j-1]
    j += i+1
  if sum_b%2 != a[i]:
    c.append(i+1)
    b[i] = 1
    m += 1

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

Submission status: Accepted

Solution code:
def abc_134d(N, A):
	index = N
	result = [0 for _ in range(N)]

	while index > 0:
		index -= 1
		j = 2
		sumval = 0

		if (index + 1) <= N // 2:
			while (index + 1) * j <= N:
				sumval += result[(index + 1) * j - 1]
				j += 1
			result[index] = (sumval % 2 + A[index]) % 2
		else:
			result[index] = A[index]

	if 1 not in result:
		print(0)
	else:
		buf = [i + 1 for i in range(N) if result[i] == 1]
		print(len(buf))
		[print(str(val), end=" ") if i < len(buf) - 1 else print(str(val)) for i, val in enumerate(buf)]


if __name__ == "__main__":
	N = int(input())
	A = [int(val) for val in input().split()]
	abc_134d(N, A)

Submission status: Accepted

Solution code:
M = int(input())
a = list(map(int,input().split()))
a = [None]+a
b = [M-k for k in range(M)]
c = [0 for k in range(M+1)]
h = 0
for s in b:
	w = M // s
	wa = 0
	for k in range(w-1):
		wa += c[s*(k+2)]
	if wa % 2 == a[s]:
		c[s] = 0
	else:
		c[s] = 1
		h += 1
print(h)
for k in range(1,len(c)):
	if c[k] == 1:
		print(k, end=" ")

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    a = list(map(int,input().split()))
    x = [0]*n
    b = set()

    for j in range(n):
        i = n - j -1
        if sum(x[i::i+1])%2 != a[i]:
            x[i] = 1
            b.add(i+1)
    cnt = len(b)

    if cnt == 0:
        print(0)
    else:
        print(cnt)
        print(*b)


resolve()

Submission status: Accepted

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

dp = [0 for i in range(N+1)]
ball = [0 for b in range(N+1)]

if N % 2 == 0:
    for i in range(N//2):
        ball[-i-1] = A[-i-1]
    num = N//2
else:
    for i in range(N//2+1):
        ball[-i-1] = A[-i-1]
    num = N//2


while num >= 1:
    c = num
    mod = 0
    k = 1
    while c*k <= N:
        mod += ball[c*k]
        k += 1
    if mod % 2 == 0:
        if A[num-1] == 1:
            ball[num] += 1
    else:
        if A[num-1] == 0:
            ball[num] += 1
    num -= 1

M = sum(ball)
print(M)
for i in range(N+1):
    if ball[i] != 0:
        print(i)

Submission status: Accepted

Solution code:

n = int(input())

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


for i in range(n-1, -1, -1):
    tmp = sum(ans[i::i+1])
    if tmp % 2 == a[i]:
        continue
    else:
        b.add(i+1)
        ans[i] = 1

cnt = len(b)


if cnt == 0:
    print(0)
else:
    print(cnt)
    print(*b)

Submission status: Accepted

Solution code:
import math as math

N = int(input())
A = list(map(int, input().split()))
ANS = [0]*len(A)
for i in range(math.floor(N/2)+1,N):
    ANS[i] = A[i]

fnum=math.floor(N/2)
for i in range(fnum,-1,-1):
    j = i + 1
    tsum=A[i]
    for k in range(j,N+1,j):
        tsum+=ANS[k-1]
    ANS[i]=tsum%2

#print(ANS)
anslist=[]
for i in range(N):
    if ANS[i]==1:
        anslist.append(i+1)
 
print(len(anslist))
for s in anslist:
    print(s, end =" ")

Submission status: Accepted

Solution code:
import math
n=int(input())

a=[0 for i in range(n)]
b=[0 for j in range(n)]
a=input().split()

bsum=0
c=[]
for i in range(n):
    index=n-i-1
    m=math.floor(n/(index+1))
    sum=0
    for j in range(m-1):
        sum+=b[(index+1)*(j+2)-1]
    b[index]=abs(sum%2-int(a[index]))
    if b[index]==1:
        c.append(index+1)
    bsum+=b[index]

print(bsum)
print(' '.join(map(str, c)))

Submission status: Accepted

Solution code:
#D
N = int(input()) 
a = list(map(int,input().split()))
box = [0] * N 
result = []
for i in range(N-1, -1, -1):
    aisum = 0 
    for j in range(i, N, i+1):
        aisum += box[j] 
    if aisum%2  != a[i]%2: 
        box[i] = 1 
        result.append(i+1)
    else: 
        box[i] = 0 
print(len(result))
if len(result) != 0:
    print(' '.join(map(str, result)))

Submission status: Accepted

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

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

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

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

print(len(anslist))
print(*anslist)

Submission status: Accepted

Solution code:

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

r = l[::-1]
ans = [0] * n
for i in range(n):
    s = 0
    for j in range(n//(n-i)):
        s += ans[n-i + j*(n-i)-1]

        # print(j,n-i + j*(n-i)-1)
    else:
        if s%2 != l[n-i-1]:
            ans[n-i-1]+=1
            ans[n-i-1]%=2
ansL = []
R = 0
for i , a in enumerate(ans):
    if a == 1:
        R+=1
        ansL.append(i+1)
print(R)
if R >0:
    print(*ansL)

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,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())
a = list(map(int,input().split()))

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

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