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

ball = [0]*n
for i in range(n)[::-1]:
    _sum=0
    for g in range(1,n+1):
        if (i+1)*g-1<n:
            _sum+=ball[(i+1)*g-1]
        else:
            break
    if _sum%2!=a[i]:
        ball[i]=1

print(sum(ball))
if sum(ball)!=0:
    print(*[g+1 for g in range(len(ball)) if ball[g]!=0])

Submission status: Accepted

Solution code:

N = int(input())
A = list(map(int, input().split()))
B = set()

for i in list(range(1, N+1))[::-1]:
  tmp = i
  cnt = 0
  while tmp <= N:
    if tmp in B:
      cnt += 1    
    tmp += i

  if cnt % 2 != A[i-1]:
    B.add(i)

len_b = len(B)
if len_b == 0:
  print(0)
else:
  print(len_b)
  print(*sorted(list(B)))

Submission status: Accepted

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

for i in range(n, 0, -1):
  x = 0
  for j in range(2*i, n+1, i):
    x+=c[j-1]
  if a[i-1] != x%2:
    c[i-1] += 1
    b.add(i)
print(len(b))
print(*b)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    N = I()
    a = LI()
    b = [0] * N

    for i in range(N-1, -1, -1):
        total = 0

        for cur in range(i, N, i+1):
            # print(i + 1, '->', cur + 1)
            total += b[cur]

        if a[i] != total % 2:
            b[i] = 1
            # print(i+1, 'in', a[i],  total)
        # print(*b)

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
choice=[0]*n
ans=[]
cnt=0
for i in reversed(range(n)):
    a=i+1
    c=0
    a+=i+1
    while a<=n:
        c+=choice[a-1]
        a+=i+1
    if c%2!=A[i]:
        choice[i]+=1
        ans.append(i+1)
        cnt+=1
if cnt==0:
    print(0)
else:
    print(cnt)
    ans.sort()
    print(*ans, sep=' ')

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
choice=[0]*n
ans=[]
cnt=0
for i in range(n-1,-1,-1):
    a=i+1
    c=0
    a+=i+1
    while a<=n:
        c+=choice[a-1]
        a+=i+1
    if c%2!=A[i]:
        choice[i]+=1
        ans.append(i+1)
        cnt+=1
if cnt==0:
    print(0)
else:
    print(cnt)
    ans.sort()
    print(*ans, sep=' ')

Submission status: Accepted

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

nball = [0] * (N + 1)  # nball[i] ... i番目の箱に入っているボールの数

nball[N] = a[N]

for i in range(N - 1, 0, -1):
    if 2 * i <= N:
        nball[i] = ( a[i] + sum(nball[2 * i : N + 1 : i]) ) % 2  # nball[2*i] + nball[3*i] + ... + nball[floor(N/i)*i]
    else:
        nball[i] = a[i]

M = 0
b = []
for i in range(N + 1):
    M += nball[i]
    if nball[i] > 0:
        b.append(i)

print(M)
if len(b) > 0:
    print(' '.join(map(str, b)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


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

b = [0] * (n + 1)
for i in range(n, 0, -1):
  dprint('i', '=', i)
  t = 0
  if n // 2 < i:
    b[i] = a[i]
  else:
    for j in range(i, n + 1, i):
      dprint('j', '=', j)
      t += b[j]
    b[i] = (a[i]+t) % 2

dprint(b)

print(b.count(1))
for i, x in enumerate(b):
  if x == 1:
    print(i, end=' ')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
aN = 0
al = [0] * (N + 1)
ans = []
for i in reversed(range(1, N + 1)):
    total = 0
    for j in range(2 * i, N + 1, i):
        total += al[j]
    if total % 2 != a[i - 1]:
        al[i] = 1
        ans.append(i)
ans.reverse()
print(len(ans))
for i in ans:
    print(i, end=' ')

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(N)]
for i in range(N, 0, -1):
  S = sum(B[(m+1)*i-1] for m in range(1, N//i))
  B[i-1] = (A[i-1] + S) % 2
C = []
for i in range(N):
  if B[i] == 1:
    C.append(i+1)
print(len(C))
for i in range(len(C)):
  if i != len(C) - 1:
    print(C[i], end = ' ')
  else:
    print(C[i])

Submission status: Accepted

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

ans = []

i = 0
while i < n:
    j = k = n - i
    add = j
    times = n - i
    cnt = 0

    if j == 1:
        cnt = sum(b)
    else:
        while j <= n:
            cnt += b[j-1]
            j += add

    #print(k, a, cnt, b)
    if cnt % 2 != a[k-1]:
        b[k-1] = 1
        ans.append(k)
    else:
        b[k-1] = 0

    i += 1

print(len(ans))
if len(ans) > 0: print(*ans[::-1])

Submission status: Accepted

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

N = int(input())
a = list(map(int,input().split()))
a.insert(0,-1)

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

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

print(M)
[print(x) for x in b]

Submission status: Accepted

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

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

#box = [0]*(N+1)

for i in range(N,0,-1):
    k=2
    temp=a[i-1]
    #print(123,i,ball)
    while i*k<=N:
        if a[i*k-1]==1:
            temp = (temp+1)%2
        k+=1
    a[i-1] = temp
#print(box)
M=0
b=[]
for i in range(1,N+1):
    if a[i-1]==1:
        M+=1
        b.append(i)

print(M)
[print(x) for x in b]

Submission status: Accepted

Solution code:
N=int(input())
a = list(map(int,input().split()))
if N == 1:
    print(a[0])
    if a[0] == 1:
        print(1)
else:
    ball = [0 for i in range(N)]
    ans = []
    for i in range(N-1,-1,-1):
        sumi = sum(ball[2*i+1::i+1])
        if a[i] != sumi%2:
            ball[i] = 1
            ans.append(i+1)
    ans.sort()
    print(len(ans))
    if len(ans) != 0:
        print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = []
arr = [-1] * N
for i in range(N, 0, -1):
  s = 0
  j = i * 2
  while j <= N:
    s += arr[j - 1]
    j += i
  if s % 2 != a[i - 1]:
    arr[i - 1] = 1
    b.append(i)
  else:
    arr[i - 1] = 0
print(len(b))
print(*b)

Submission status: Accepted

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

r = [0] * N


def f(n):
    """
    nの倍数のボールの数
    """
    cnt = 0
    t = n + n
    while t <= N:
        cnt += r[t-1]
        t += n
    return cnt


for i in range(N):
    n = N - i
    x = f(n)
    if x % 2 == A[n-1]:
        pass
    else:
        r[n-1] += 1

# print(r)

ans = []
for i, ri in enumerate(r):
    if ri == 1:
        ans.append(str(i+1))

if len(ans) == 0:
    print(0)
else:
    print(len(ans))
    print(" ".join(ans))

Submission status: Accepted

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

r = [0] * N


def f(n):
    """
    nの倍数のボールの数
    """
    cnt = 0
    i = 2
    while n * i <= N:
        cnt += r[n*i-1]
        i += 1
    return cnt


for i in range(N):
    n = N - i
    x = f(n)
    if x % 2 == A[n-1]:
        pass
    else:
        r[n-1] += 1

# print(r)

ans = []
for i, ri in enumerate(r):
    if ri == 1:
        ans.append(str(i+1))

if len(ans) == 0:
    print(0)
else:
    print(len(ans))
    print(" ".join(ans))

Submission status: Accepted

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

for n in range(N):
    m = N - n
    q = N // m
    r = 0
    for q0 in range(2, q + 1):
        r += b[m * q0] % 2
    b[m] = (a[m] - r) % 2
print(sum(b))
ans = []
for n in range(N):
    m = N - n
    if b[m] == 1:
        ans.append(m)
print(*ans)

Submission status: Accepted

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

r = [None] * N
# A = A[::-1]  # 扱いやすくするためにひっくり返す

# nの倍数の箱に入っているボールの個数
# (nは含まない)
def f(n):
    i = 2
    cnt = 0
    while n * i <= N:
        # print('-', n, i, r)
        cnt += r[(n * i)-1]
        i += 1
    # print('--', n, cnt, r)
    return cnt

n = N
while n > 0:
    c = f(n)
    # print(n, c, A[n-1])
    if c % 2 == A[n-1]:
        r[n-1] = 0
    else:
        r[n-1] = 1
    n -= 1

# print(r)

r_a = []
r_cnt = r.count(1)
print(r_cnt)
for i, ri in enumerate(r):
    if ri == 1:
        r_a.append(str(i+1))

if r_cnt != 0:
    print(" ".join(r_a))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    b = [0]*(n+1)
    for i in range(1,n+1)[::-1]:
        x = i
        s = 0
        while x <= n:
            s ^= b[x]
            x += i
        b[i] = s^a[i-1]
    ans = [i for i in range(1,n+1) if b[i]]
    print(len(ans))
    print(*ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Bo = [0 for _ in range(n)]
Ans = []

for i in range(n-1, -1, -1):
    tot = sum(Bo[i::i+1])

    if (tot % 2 == A[i]):
        pass
    elif (tot % 2 != A[i]):
        Ans.append(str(i+1))
        Bo[i] += 1
    else:
        pass
if len(Ans) ==0:
    print(0)
else:
    print(len(Ans))
    print(' '.join(Ans))

Submission status: Accepted

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

a = [0]+a
ball = [0]+ball

for i in range(N,0,-1):
  num = 0
  for j in range(i,N+1,i):
    num += ball[j]
  if num%2 != a[i]:
    ball[i] += 1
    
print(sum([1 for i in range(len(ball)) if ball[i]]))
num_list = []
for i in range(1,len(ball)):
  if ball[i]:
    num_list.append(i)
    
print(*num_list)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = [0]*(n+1)
m = 0
ans = []
for i in reversed(range(1,n+1)):
  tmp = 0
  for j in range(2*i,n+1,i):
    if x[j] == 1:
      tmp += 1
  if tmp % 2 != a[i-1]:
    x[i] = 1
    m += 1
    ans.append(i)
print(m)
for i in ans:
  print(i,end=" ") 
"""
#no ball
if all(i == 0 for i in x):
  print(0)
  exit()
#else
for i in range(1,n+1):
  if x[i] == 1:
    print(i,end=" ")
"""

Submission status: Accepted

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

B = [0] * (M + 1)

for i in range(M, 0, -1):
  j = 2
  tmp = 0
  while i * j <= M:
    B[i] += B[i * j]
    j += 1
  B[i] += A[i]
  B[i] %= 2
  
answer = []
for i in range(M + 1):
  if B[i]:
    answer.append(i)

if len(answer):
  print(len(answer))
  print(*answer)
else:
  print(0)

Submission status: Accepted

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

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

print(sum(b))
print(' '.join(map(str, ans)))

Submission status: Accepted

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

box=[0]*n
ans=[]
for i in range(n,0,-1):
    sum_=0
    for j in range(1,n+1):
        if j*i>n:
            break
        sum_+=box[j*i-1]
    if sum_%2!=a[i-1]:
        box[i-1]=1
        ans.append(i)

print(len(ans))
print(' '.join(list(map(str,ans))))

Submission status: Accepted

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

box=[0]*n
ans=[]
for i in range(n,0,-1):
    sum_=0
    for j in range(1,n+1):
        if j*i>n:
            break
        sum_+=box[j*i-1]
    if sum_%2!=a[i-1]:
        box[i-1]=1
        ans.append(i)

print(len(ans))
print(' '.join(list(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 reversed(range(1, N + 1)):
    ball = 0
    base = i + 1

    for j in range(i, N + 1, i):
        ball += B[j]

    if ball % 2 != A[i]:
        B[i] = 1

print(sum(B))
print(*[i for i, b in enumerate(B) if b == 1], sep=' ')

Submission status: Accepted

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

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

ans = []
for i in range(N):
  if b[i] == 1:
    ans.append(i+1)
    
print(len(ans))
print(' '.join(map(str, ans)))

Submission status: Accepted

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

ans=[0]*(N+1)

for i in range(N,0,-1):
    cnt=0
    for j in range(i*2,N+1,i):
        cnt+=ans[j]
    ans[i]=cnt&1^A[i-1]

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

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in input().split()]
S = [0]*N
cnt = 0
for i in range(N-1, -1, -1):
  A = S[i::i+1]
  if sum(A)%2 == B[i]:
    continue
  elif sum(A)%2 == 0 and B[i] == 1:
    S[i] += 1
    cnt += 1
  elif sum(A)%2 == 1 and B[i] == 0:
    S[i] += 1
    cnt += 1
print(cnt)
l = []
for i in range(N):
  if S[i] == 1:
    l.append(i+1)
print(" ".join(map(str,l)))

Submission status: Accepted

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

b = [0 for i in range(N//2)]+a[N//2:]

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

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

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

Submission status: Accepted

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

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

ans_n = 0
ans_l = []
for i in range(N+1):
    if b[i]:
        ans_n += 1
        ans_l.append(str(i))

print(ans_n)
print(' '.join(ans_l))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    a=list(map(int,input().split()))
    l=[0]*N
    l2=[]
    ans=0
    for i,x in enumerate(reversed(a)):
        z=N-i
        c=0
        for j in range(2,N//z+1):
            c+=l[z*j-1]
        if c%2!=x:
            l[N-1-i]+=1
            ans+=1
            l2.append(N-i)
    print(ans)
    print(*l2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
#https://atcoder.jp/contests/abc138/tasks/abc138_d
#D - Ki
"""
need to consider the case that ticket is not enough to lower everything
"""
N = gi()
A = [0] * (N + 5)
bs = [0] * (N + 5)
for i in range(1, N + 1):
    A[i] = gi()

ans = []
for i in range(N, 0, -1):
    tc = 0
    mul = 1
    while mul * i <= N:
        tc += bs[mul * i]
        mul += 1
    if (tc % 2 != A[i]):
        bs[i] = 1
        ans.append(i)

print(len(ans))
for v in ans:
    print("%d " % (v), end="")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
BOX = [None for i in range(N)]
ANS_LIST = []
for i in range(N-1,-1,-1):
    loop = N//(i+1)
    cnt = 0
    for j in range(loop):
        if BOX[(i+1)*(j+1)-1]!=None:
            cnt+=BOX[(i+1)*(j+1)-1]
    BOX[i]=(cnt-A[i])%2

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

print(sum(BOX))
print(*ANS_LIST)

Submission status: Accepted

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

i = n // 2
BOXES[i:] = A[i:]

j = i
for _ in range(i):
    k = j - 1
    count = 0
    while True:
        count += BOXES[k]
        k += j
        if k >= n:
            break
    if count % 2 != A[j - 1]:
        BOXES[j - 1] = 1
    j -= 1

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

Submission status: Accepted

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

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


print(sum(ans))
f = 0
for i in range(N+1):
    if ans[i] == 0: continue
    if f: print(' ')
    print(i, end ='')
    f = 1
if f:print()

Submission status: Accepted

Solution code:
N, = map(int, input().split())
As = [0] + list(map(int, input().split()))
Bs = [0] * (N+1)
for i in range(N):
    i = N - i
    tmp = 0
    for j in range(N//i-1):
        tmp += Bs[i * (j+2)]
    tmp %= 2
    if As[i]:
        Bs[i] = 1 - tmp
    else:
        Bs[i] = tmp
print(sum(Bs))
rs = []
for i, v in enumerate(Bs):
    if v:
        rs.append(i)
print(*rs)

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):
    p = A[i]
    j = i + 1
    while i < N:
        if B[i]:
            p ^= 1
        i += j
    B[j - 1] = p

S = [i + 1 for i, c in enumerate(B) if c]

print(len(S))
print(*S)

Submission status: Accepted

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

boxes=[0]*n #if ball in boxes[i-1]=boxes no.i
'''
b=[]
#m=len(b)
i=n #iの番号が書いた箱、インデックスはa[i-1]について
while i>=1:
	count=a[i-1]
	for j in range(i+1,n+1):
		if j%i==0:
			count+=boxes[j-1]
	boxes[i-1]=count%2
	if boxes[i-1]:
		b.append(i)
	i-=1
#print(boxes)

print(len(b))
print(*b) #space区切り
'''
for i in reversed(range(n)):
	boxes[i]=(a[i]+sum(boxes[i::i+1]))%2

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
rev_A = A[::-1]

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

for i in range(N, 0, -1):
    i -= 1
    
    if i >= N//2:
        box[i] = A[i]
    else:
        ans = A[i]
        for j in range((i+1)*2-1, N, i+1):
            ans += box[j]
        box[i] = ans % 2

ans_count = 0
ans_numbers = []
for i, count in enumerate(box):
    if count == 1:
        ans_count += 1
        ans_numbers.append(i + 1)

print(ans_count)
if ans_count != 0:
    print(*ans_numbers)

Submission status: Accepted

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

for i in range(n,0,-1):
    cnt = 0
    x = i
    while x <= n:
        if ball[x-1] == 1:
            cnt += 1
        x += i
    if cnt%2 != a[i-1]:
        ball[i-1] = 1
        ans.append(i)

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

Submission status: Accepted

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

for i in range(n,0,-1):
    cnt = 0
    x = i
    while x <= n:
        if ball[x-1] == 1:
            cnt += 1
        x += i
    if cnt%2 != a[i-1]:
        ball[i-1] = 1
        ans.append(i)

m = len(ans)
print(m)
if m != 0:
    for b in ans:
        print(b,end=" ")
    else:
        print("")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
al = list(map(int, input().split()))

bl = [0]*n
for i in range(n,0,-1):
    if i*2>n:
        if al[i-1]>0:
            bl[i-1] = 1
        continue

    c = 2
    s = 0
    while i*c<=n:
        s += bl[i*c-1]
        c += 1
    if al[i-1]==1:
        bl[i-1] = 1 if s%2==0 else 0
    else:
        bl[i-1] = 0 if s%2==0 else 1

res = []
for i in range(1,n+1):
    if bl[i-1]>0:
        res.append(i)

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

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):
  x=(sum(ans[i::i+1]))%2
  if x!=a[i]:
    ans[i]=1
print(sum(ans))
for i in range(n):
  if ans[i]==1:
    print(str(i+1)+" ",end="")

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ls = [0] * n
    ans = []

    for i in range(n)[::-1]:
        if (sum(ls[i::i+1]) % 2) != a[i]:
            ls[i] = 1
            ans.append(i+1)
    print(sum(ls))
    if ans:
        print(*ans[::-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ls = [0] * n
    ans = []

    for i in range(n-1, -1, -1):
        if (sum(ls[i::i+1]) % 2) != a[i]:
            ls[i] = 1
            ans.append(i+1)
    print(sum(ls))
    if ans:
        print(*ans[::-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ls = [0] * n

    for i in range(n-1, -1, -1):
        if (sum(ls[i::i+1]) % 2) != a[i]:
            ls[i] = 1
    sum_ls = sum(ls)
    print(sum_ls)
    if sum_ls:
        print(*[i+1 for i, v in enumerate(ls) if v == 1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    n_half = n // 2
    a = list(map(int, input().split()))
    ls = [0] * n
    ans = []

    for i in range(n-1, -1, -1):
        ai = a[i]
        if ai > n_half:
            ls[i] = ai
            ans.append(i+1)
        elif (sum(ls[i::i+1]) % 2) != ai:
            ls[i] = 1
            ans.append(i+1)
    print(sum(ls))
    if ans:
        print(*ans[::-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    n_half = n // 2
    a = list(map(int, input().split()))
    ls = [0] * n
    ans = []

    for i in range(n-1, -1, -1):
        if (sum(ls[i::i+1]) % 2) != a[i]:
            ls[i] = 1
            ans.append(i+1)
    print(sum(ls))
    if ans:
        print(*ans[::-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#箱の状態を記録しておく配列
box=[0]*n


for i in range(n):
  num=n-i

  #まず割って、その数より大きい倍数がいくつあるか探る
  baisu=n//num

  if baisu==1:
    box[num-1]=a[num-1]

  #1～baisu倍の箱の状態を調べる。
  temp=0
  for j in range(2,baisu+1):
    temp+=box[num*j-1]
  box[num-1]=abs(temp%2-a[num-1])

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

if sum(ans)!=0:
  print(len(ans))
  print(*ans)
else:
  print("0")

Submission status: Accepted

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

    r = []
    for i in reversed(range(N)):
        t = sum(B[i::i + 1]) & 1
        B[i] = abs(A[i] - t)
        if B[i]:
            r.append(i)
    print(len(r))
    if r:
        print(' '.join(str(i + 1) for i in r))

main()

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):
        tmp = 0
        for j in range(i,N+1,i):
            tmp += B[j]
        B[i] = (tmp % 2) ^ A[i]

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

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



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans = [0]*N
for i in range(N):
    n = N - i #1~N
    coun = sum(ans[n-1::n])%2
    if A[n-1] != coun:
        ans[n-1] = 1
n = sum(ans)
st = " ".join(["" if n==0 else str(i+1) for i,n in enumerate(ans)])
print(n)
print(st)

Submission status: Accepted

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

#箱の状態を記録しておく配列
box=[0]*n


for i in range(n):
  num=n-i

  #まず割って、その数より大きい倍数がいくつあるか探る
  baisu=n//num

  if baisu==1:
    box[num-1]=a[num-1]

  #1～baisu倍の箱の状態を調べる。
  temp=0
  for j in range(2,baisu+1):
    temp+=box[num*j-1]
  box[num-1]=abs(temp%2-a[num-1])

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

if sum(ans)!=0:
  print(len(ans))
  print(*ans)
else:
  print("0")

Submission status: Accepted

Solution code:
def main():

    N = int(input())
    a = {i: inp for i, inp in enumerate(map(int, input().split()), 1)}
        
    b = {i : 0 for i in range(1, N+1)}
    ret = []

    for i in range(N, 0, -1):
        sum_multiple = 0
        cursor = 2
        while i * cursor <= N:
            sum_multiple += b[i * cursor]
            cursor += 1

        if a[i] == 1:
            if sum_multiple % 2 == 0:
                b[i] = 1
                ret.append(i)
        else:
            if sum_multiple % 2:
                b[i] = 1
                ret.append(i)

    M = len(ret)
    print(M)
    if M:
        ret = ' '.join([str(i) for i in ret])
        print(ret)

if __name__=="__main__":
    main()