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 = [int(i) for i in input().split()]
arr = [0 for _ in range(n)]
for i in reversed(range(n)):
    s = 0
    for j in range(i, n, i+1):
        s += arr[j]
    s %= 2
    if a[i] != s:
        arr[i] = 1
print(sum(arr))
for i in range(n):
    if arr[i] == 1:
        print(i+1, end=' ')
print('')

Submission status: Accepted

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

def main():
    N = int(input())
    b = list(map(int, input().split()))
    lst = b[:]
    for i in range(N,0,-1):
        j = i
        a = 0
        while j <=N: a, j = a^lst[j-1], j+i
        lst[i-1] = a
    ans = [i+1 for i in range(N) if lst[i]]
    print(len(ans))
    print(*ans)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
	readline=stdin.readline
	N=int(readline())
	a=list(map(int,readline().split()))
	b=[0]*N
	for i in range(N):
		n=N-i
		count=0
		for k in range(n,N+1,n):
			if k==n:
				pass
			else:
				count+=b[k-1]
		if count%2!=a[n-1]:
			b[n-1]=1
		else:
			b[n-1]=0
	
	res=[]
	M=0
	for i in range(N):
		if b[i]==1:
			res.append(i+1)
			M+=1
	
	print(M)
	print(*res)
if __name__=="__main__":
	main()

Submission status: Accepted

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

box = [0] * N

for i in range(N-1, -1, -1):
    cnt = 0
    tmp = i + 1
    while tmp <= N:
        cnt += box[tmp - 1]
        tmp += (i + 1)
    
    if cnt  % 2 != A[i]:
        box[i] = 1

ans = [idx+1 for idx in range(N) if box[idx] == 1]

print(len(ans))

if ans:
    print(*ans)

Submission status: Accepted

Solution code:
import sys

def div(n):
    if n == 1: return [1]
    d = [1]
    for k in range(2, n):
        if k ** 2 > n: break
        if n % k == 0:
            if k ** 2 == n: d.append(k)
            else: 
                d.append(k)
                d.append(n // k)
    return d

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    SumB = [0] * N
    Ans = []
    count = 0

    for i in reversed(range(N)):
        if SumB[i] % 2 == A[i]: continue
        elif (SumB[i] + 1) % 2 == A[i]:
            Ans.append(i + 1)
            count += 1
            d = div(i + 1)
            for j in d: SumB[j - 1] += 1
        else:
            print(-1)
            break
    else: 
        Ans.sort()
        print(count)
        print(" ".join(map(str, Ans)))
        

    return 0
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
res=[0]*N
for i in range(N,0,-1):
    cnt=0
    for times in range(2,N//i+1):
        cnt+=res[i*times-1]
    res[i-1] = 0 if cnt%2==a[i-1] else 1
print(sum(res))
for i in range(N):
    if res[i]==1:
        print(i+1,end=" ")
print()

Submission status: Accepted

Solution code:
N = int(input())
arr = list(int(x) for x in input().split())
flag = [-1] * N
ans = []

# N-1から0までループ
for i in range(N-1,-1,-1):
    # ボールの個数
    sum = 0

    # iの倍数のボールの数を確かめる
    for j in range(i,N,i+1):
        # 自身は省く
        if j == i:
            continue
        else:
            if flag[j] == 1:
                sum += 1

    # ボールを入れるかの判定
    if sum % 2 == arr[i]:
        flag[i] = 0
    else:
        flag[i] = 1
        
        # ボールを入れるインデックスを追加
        ans.append(i+1)

# ボールを何個入れたか
num = len(ans)

if num == 0:
    print(num)
else:
    print(num)
    print(*ans)

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):
  sum=0
  for j in range(i+i,n+1,i):
    sum^=b[j]
  b[i]=sum^a[i]
ans=[]
for i in range(1,len(b)):
  if b[i]:
    ans.append(i)
print(len(ans))
print(*ans)

Submission status: Accepted

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

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

print(sum(b))
print(*ans)

Submission status: Accepted

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

b = [0]*n
for i in range(n)[::-1]:
    tmp = 0
    for j in range(n//(i+1)):
        tmp += b[(i+1)*(j+1)-1]
    if tmp%2 != a[i]:
        b[i] += 1

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

Submission status: Accepted

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

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

print(sum(ans))
print(' '.join(str(i+1) for i in range(n) if ans[i]))

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    a=list(map(int,input().split()))
    table=[0]*N
    result=0
    result_li=[]
    for i in range(N):
        i=N-i
        count=0
        for j in range(i,N+1,i):
            count+=table[j-1]
        if count%2==a[i-1]:
            pass
        else:
            table[i-1]=1
            result+=1
    for i in range(N):
        if table[i]==1:
            result_li.append(i+1)
    print(result)
    if len(result_li)>=1:
        print(" ".join(map(str,result_li)))

if __name__=="__main__":
    main()

Submission status: Accepted

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

B=[0]*(n+1)
C,cnt=[],0
for i in range(1,n+1)[::-1]:
    sum_list=sum([B[j] for j in range(i,n+1,i)])
    if sum_list%2!=A[i-1]:
        B[i]=1
        cnt +=1
        C.append(i)

print(cnt)
print(*C[::-1])

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
A = [0] + a
B = [0]*(N+1)
putBall = []

for i in range(N, 0, -1):
    if sum(B[i::i])%2 != A[i]:
        B[i] = 1
        putBall.append("%d" % i)

print(sum(B))
print(*putBall)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
A = [0] + a
B = [0]*(N+1)
putBall = []

for i in range(N, 0, -1):
    cnt = 1
    multiple = i
    tmp = 0
    if sum(B[i::i])%2 != A[i]:
        B[i] = 1
        putBall.append("%d" % i)

print(sum(B))
print(*putBall)

Submission status: Accepted

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

i = n-1
while i >= 0:
    cnt = 0
    for j in range(1, n+1):
        if (i+1) * j - 1  >= n:
            break
        cnt += ans[(i+1)*j-1]
    if cnt % 2 != a[i]:
        ans[i] = 1
    i -= 1
    #print(cnt)
print(ans.count(1))
for i in range(n):
    if ans[i] == 1:
        print(i+1)

Submission status: Accepted

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

i = n
while i > 0:
    cnt = 0
    for j in range(1, n+1):
        if i * j  > n:
            break
        cnt += ans[i*j]
    if cnt % 2 != a[i-1]:
        ans[i] = 1
    i -= 1
    #print(cnt)
print(ans.count(1))
for i in range(1,n+1):
    if ans[i] == 1:
        print(i)

Submission status: Accepted

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

output_list = []

for i in reversed(range(N)):
    current_sum = 0
    target_num = i+1
    target_num_idx = 0
    for j in range((N)//(target_num)):
        target_num_idx = target_num_idx + target_num
        current_sum += Bn[target_num_idx -1]
    if current_sum % 2 != Bn[i]:
        if Bn[i] == 1:
            Bn[i] = 0
        else:
            Bn[i] = 1
    if Bn[i] == 1:
        output_list.append(target_num)
print(len(output_list))
output_list.reverse()
print(' '.join(map(str,output_list)))

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):
  b[i]=(a[i]+sum(b[i::i+1]))%2
l=[x+1 for x,y in enumerate(b) if y==1]
print(len(l))
print(*l)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc134/tasks/abc134_d
# よくわからん本当に緑diff?
# とりあえずエラトステネスの篩のように倍数を列挙する感じでほぼ愚直にやる
# N/2以上の整数に関しては即座に答えが決まる。
# 答えが決まった部分より下を引いていけば良いのでは？

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = [0] + read_ints()

B = [0] * (N + 1)
B[(N // 2) + 1:] = A[(N // 2) + 1:]


for i in range(N // 2, 0, -1):
    a = A[i]
    j = i + i
    while j < N + 1:
        a -= B[j]
        j += i
    B[i] = a % 2
# print(B)


print(sum(B))
for i, b in enumerate(B):
    if b:
        print(i, end=' ')

Submission status: Accepted

Solution code:
# 後ろから見ていく
# N番目の箱の倍数は１つしかないため、確定できる。
# 後ろ半分は倍数の箱を持たない
# 後ろから
# これの繰り返し

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

b=[-1]*h+a[h:]
for i in range(h,-1,-1):
  # 自分を除く自分の倍数を数える
  jsum=0
  for j in range((i+1)*2-1,len(b),i+1):
    jsum^=b[j]
  b[i]=a[i]^jsum

print(sum(b))
for i in range(n):
  if b[i]:
    print(i+1)

Submission status: Accepted

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

balls = [0] * n

def get_b(num):
    cnt=0
    now=num
    while True:
        cnt+=balls[now-1]
        now+=num
        if now > n:
            break
    return cnt

for i in range(n,0,-1):
    now_cnt=get_b(i)
    if now_cnt%2 != a[i-1]:
        balls[i-1]=1

print(sum(balls))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def divisor(n):
        i = 1
        table = []
        while i * i <= n:
            if n % i == 0:
                table.append(i)
                table.append(n // i)
            i += 1
        table = list(set(table))
        return table


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)

    def list(self):
        return self.__q

    def length(self):
        return len(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e30)


def main():
    # sys.stdin = open("Sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    B = [0] * N
    for i in reversed(range(1, N+1)):
        now = 0
        j = i
        while j <= N:
            if B[j - 1] == 1:
                now += 1
            j += i
        if now % 2 != A[i - 1]:
            B[i - 1] = 1
    print(B.count(1))
    for i in range(N):
        if B[i] == 1:
            print(i + 1)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [0] + list(map(int, input().split()))
b = set([i for i in range(N//2 + 1, N + 1) if a[i] == 1])

for i in range(N//2, 0, -1):
    if sum([1 for k in range(2, N//i + 1) if k*i in b]) % 2 != a[i]:
        b.add(i)

if len(b) > 0:
    print(len(b))
    print(' '.join(list(map(str, sorted(list(b))))))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
a = [0] + list(map(int, input().split()))
b = set([i for i in range(N//2 + 1, N + 1) if a[i] == 1])

for i in range(N//2, 0, -1):
    k, temp = 2, 0
    while k * i < N + 1:
        if k * i in b:
            temp += 1
        k += 1
    if temp % 2 != a[i]:
        b.add(i)

if len(b) > 0:
    print(len(b))
    print(' '.join(list(map(str, sorted(list(b))))))
else:
    print(0)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=[0]*n
for i in range(n):
  c=n-i
  t=0
  sum_d=sum(d[x] for x in range(c-1,n,c))
  if sum_d%2 != a[c-1]:
    d[c-1]=1

print(sum(d))
b=[]
if sum(d):
  for i in range(n):
    if d[i]>0:
      b.append(i+1)
  print(*b)

Submission status: Accepted

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
lst = [0] * (N + 1)
ans = set()
for i in range(N, 0, -1):
    tmp = (sum(lst[i::i]) % 2 + A[i - 1]) % 2
    if tmp:
        ans.add(i)
    lst[i] = tmp
print(len(ans))
print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
flag = [-1] * n
ans = []

for i in range(n-1, -1, -1):
    cnt = 0
    for j in range(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())
a=list(map(int,input().split()))

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

print(sum(res))

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

Submission status: Accepted

Solution code:
import sys

n, *a = map(int, sys.stdin.read().split())
a = [None] + a

def main():
    res = [0] * (n + 1)
    chosen = []
    for i in range(n, 0, -1):
        tmp = sum(res[i*2:n+1:i]) & 1
        if tmp ^ a[i]:
            res[i] = 1
            chosen.append(i)

    if chosen:
        m = len(chosen)
        return [m], chosen[::-1]
    else:
        return [[0]]

if __name__ == '__main__':
    ans = main()
    for a in ans:
        print(*a, sep=' ')

Submission status: Accepted

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

t=((n+1)+2-1)//2

ans=[-1]+[0 for i in range(n)]
ans[t:]=a[t:]

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

m=ans.count(1)
ans_l=[]
for i in range(n+1):
 if ans[i]==1:
  ans_l.append(i)
print(m)
if ans_l:
 print(*ans_l)

Submission status: Accepted

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

t=((n+1)+2-1)//2

ans=[-1]+[0 for i in range(n)]
ans[t:]=a[t:]

#print(a)
#print(ans)

for i in range(t-1,0,-1):
 t_sum=sum(ans[i+i::i])
# print(i,a[i],t_sum)
 if a[i]%2==t_sum%2:
  ans[i]=0
 else:
  ans[i]=1

#print(ans)

m=ans.count(1)
ans_l=[]
for i in range(n+1):
 if ans[i]==1:
  ans_l.append(i)
print(m)
if ans_l:
 print(*ans_l)

Submission status: Accepted

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

d = [0]*(int(n/2)) + a[int(n/2):]

for i in range(int(n/2), 0, -1):
    i_sum = sum(d[i-1::i])
    if a[i-1] == 1 and i_sum%2 == 0:
        d[i-1] = 1
    elif a[i-1] == 0 and i_sum%2 == 1:
        d[i-1] = 1

m = d.count(1)
print(m)
if m != 0:
    print(*[i+1 for i in range(n) if d[i] == 1])

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
ret = []
for i in range(N, 0, -1):
  if (sum(B[i-1::i])%2) != A[i-1]:
    B[i-1]= 1
    ret.append(i)
print(sum(B))
print(*ret)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)


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


def main():
    N = int(input())
    a = [-1]+list(map(int, input().split()))
    b = [0] * (N+1)
    for i in reversed(range(1,N+1)):
        total = 0
        for j in range(i,N+1,i):
            total += b[j]
        if a[i] != (total%2):
            b[i] = 1
    ans = []
    cnt = 0
    for i, n in enumerate(b):
        if n!=0:
            ans.append(i)
            cnt += 1
    print(cnt)
    print(*ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
ans = [0] * (n+1)
ans_index = set([])
for i in reversed(range(1, n + 1)):
    sum_i = sum(ans[i * 2:n + 1:i])
    if a[i-1] == (sum_i + 1) % 2:
        ans[i] = 1
        ans_index.add(i)
    elif a[i-1] == sum_i % 2:
        ans[i] = 0
    else:
        print(-1)
        sys.exit()
print(sum(ans))
if ans_index:
    print(*ans_index)

Submission status: Accepted

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

def sumN(n,N,f):
	total = 0
	i = n
	while i < N:
		total += f[i]
		i += n+1

	if total % 2:
		return 1
	else:
		return 0

def main():
	N = int(input())
	a = list(map(int,input().split()))
	ball = []
	ballNum = 0
	f = [0]*N

	for i in reversed(range(0,N)):
		if (sum(f[i::i+1])%2) != (a[i] % 2):
			f[i] = 1
			ball.append(i+1)
			ballNum +=1

	if (sum(f) % 2) != (a[0] % 2):
		f[0] = 1
		ball.append(1)
		ballNum +=1

	print(ballNum)
	print(*ball)

if __name__ == "__main__":
	main()

Submission status: Accepted

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.insert(0,0)

    B = [[] for i in range(N+1)]
    B[0] = 0

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def sumN(n,N,f):
	total = 0
	i = n
	while i < N:
		total += f[i]
		i += n+1

	if total % 2:
		return 1
	else:
		return 0

def main():
	N = int(input())
	a = list(map(int,input().split()))
	ball = []
	ballNum = 0
	f = [0]*N

	for i in reversed(range(1,N)):
		if sumN(i,N,f) != (a[i] % 2):
			f[i] = 1
			ball.append(i+1)
			ballNum +=1

	if (sum(f) % 2) != (a[0] % 2):
		f[0] = 1
		ball.append(1)
		ballNum +=1

	print(ballNum)
	print(*ball)

if __name__ == "__main__":
	main()

Submission status: Accepted

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.insert(0,0)

    B = [[] for i in range(N+1)]
    B[0] = 0

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(N)[::-1]:
    n = i+1
    if b[i]:
        ans.append(n)
        for j in range(1, int(n**0.5)+1):
            if n%j==0:
                b[j-1] ^= 1
                if j!=n//j:
                    b[n//j-1] ^= 1

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

Submission status: Accepted

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

for i in range(N)[::-1]:
    n = i+1
    if b[i]:
        ans.append(n)
        
        tmp = 1
        while tmp*tmp <= n:
            if n % tmp == 0:
                b[tmp-1] ^= 1
                if tmp != n//tmp:
                    b[n//tmp-1] ^= 1
            tmp += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  ans=[0]*n

  ind=n
  for i in range(n):
    sm=0
    for j in range(2,n+1):
      if ind*j>n:
        break
      else:
        sm+=ans[ind*j-1]
    ans[ind-1]=(l[ind-1]+sm)%2
    ind-=1
    # print(ans,ind)

  # print(ans)

  _ans=[]
  for i,x in enumerate(ans):
    if x==1:
      _ans.append(i+1)

  ln=len(_ans)
  print(ln)
  if ln!=0:
    print(' '.join([str(x) for x in _ans]))

main()
# print(main())

Submission status: Accepted

Solution code:
import unittest
from io import StringIO
import sys


def resolve():
    input = sys.stdin.readline
    N = int(input())
    # S = input()
    # A, B = map(int, input().split())
    A = list(map(int, input().split()))

    # P = []
    # S = []
    # for i in range(N):
    #     pp, ss = map(int, input().split())
    #     P.append(pp)
    #     S.append(ss)

    isBalls = [0] * (N + 1)
    for k in reversed(range(1, N + 1)):
        num = sum([isBalls[k * i] for i in range(1, N // k + 1)])
        if num % 2 != A[k - 1]:
            isBalls[k] = 1

    M = sum(isBalls)
    ans = [i for i in range(1, N + 1) if isBalls[i] > 0]

    print(M)
    if ans:
        print(' '.join(map(str, ans)))

resolve()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
box = [0]*(n+1)
def c(lst,x):
  ans = 0
  now = x
  while now <= n:
    ans += lst[now]
    now += x
  return ans

for i in range(n,0,-1):
  if c(box,i)%2 != a[i-1]:
    box[i] = 1
print(sum(box))
for i in range(1,n+1):
  if box[i] == 1:
    print(i,end=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
b = [0] * N
M = 0
for i in range(N, 0, -1):
    ball = 0
    for j in range(i + i, N + 1, i):
        ball ^= b[j - 1]
    b[i - 1] = ball ^ a[i]
M = sum(b)
print(M)
for i in range(N):
    if b[i]:
        print(i + 1, end = ' ')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))
    B = [0] * (N + 1)
    for i in range(N,0,-1):
        B[i] = A[i]
        j = 2
        while i * j < (N + 1):
            B[i] ^= B[i * j]
            j += 1

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

b = [0] * n

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

c = []
for i in range(n):
    if b[i] == 1:
        c.append(i+1)
print(sum(b))
if len(c) > 0:
    print(*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):
  count = 0
  for j in range(i, N, i+1):
    count += B[j]
  if count%2 == A[i]:
    B[i] = 0
  else:
    B[i] = 1

sum = sum(B)
if sum == 0:
  print(0)
else:
  print(sum)
  ans = []
  for i in range(N):
    if B[i] == 1:
      ans.append(i+1)
  print(*ans)

Submission status: Accepted

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

B = [0]*N

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

sum = sum(B)
if sum == 0:
  print(0)
else:
  print(sum)
  ans = []
  for i in range(N):
    if B[i] == 1:
      ans.append(i+1)
  print(*ans)

Submission status: Accepted

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

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

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

sum = sum(B)
if sum == 0:
  print(0)
else:
  print(sum)
  ans = []
  for i in range(N):
    if B[i] == 1:
      ans.append(i+1)
  print(*ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int, input().split()))
a.insert(0, 0)
b=[0 for _ in range(N+1)]
for i in range(N, 0, -1):
    s=0
    for j in range(i, N+1, i):
        s=s^b[j]
    b[i]=s^a[i]
ans=[]
for i in range(1, N+1):
    if b[i]==1:
        ans.append(i)
print(len(ans))
if len(ans):
    print(" ".join(map(str, ans)))

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):
    B[i] =(A[i] + sum(B[::i])) % 2
print(sum(B))
print(*(i for i, b in enumerate(B) if b))

Submission status: Accepted

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

ans_m = 0
ans_b = []
for i in range(n-1,n//2-1,-1):
    # print(i)
    if a[i] == 1:
        b[i] = 1
        ans_m += 1
        ans_b.append(i+1)
        
        # print(i+1)

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

# print(b)

print(ans_m)
print(*ans_b)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 2  # type: int

def solve(N: int, a: "List[int]"):
    a = [0] + a
    b = [0] * (N+1)
    for i in range(N,0,-1):
        j = i*2
        n = 0
        while j <= N:
            n += b[j]
            j += i
        # print("a[i],n :", i, a[i], n)
        if a[i] == n%MOD:
            b[i] = 0
        else:
            b[i] = 1

    x = [i for i in range(1, N+1) if b[i] == 1]
    print(len(x))
    for i in x:
        print(i)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans_list = [0] * N
ans_text = ''
for i in range(N):
  # j の倍数が何個あるか
  j = N - i
  sum_j = sum(ans_list[j-1::j])
  if sum_j%2 != a_list[j-1]:
    ans_list[j-1] = 1
    ans_text += str(j) + ' '
    
    
print(sum(ans_list))
print(ans_text)

Submission status: Accepted

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

box = [0] * (N+1)
ans = []
for i in range(N,0,-1):
  work = 0
  for j in range(0,N+1,i):
    work += box[j]
    #print(i,j)
  if work % 2 != A[i-1]:
    box[i] = 1
    ans.append(i)

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

Submission status: Accepted

Solution code:
n =int(input())

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

box =[0]*n
sum=0
for i in reversed(range (n)):
  sum=0
  for j in (range(int(n/(i+1))-1)):
    sum +=box[i+(i+1)*(j+1)]
  box[i]=(sum+num[i])%2


ans = []
for i in range(n):
  if box[i]==1:
    ans.append(i+1)
print(len(ans))
ans=[str(a) for a in ans]
ans=" ".join(ans)
print(ans)

Submission status: Accepted

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

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

if ans == []:
    print(0)
else:
    print(len(ans))
    print(" ".join(map(str, ans)))