Problem:


Score : 400 points

Problem Statement

There are N empty boxes arranged in a row from left to right.
The integer i is written on the i-th box from the left (1 \leq i \leq N).

For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.

We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:

For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.

Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

a_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If a good set of choices does not exist, print -1.

If a good set of choices exists, print one such set of choices in the following format:

M
b_1 b_2 ... b_M

where M denotes the number of boxes that will contain a ball, and b_1,\ b_2,\ ...,\ b_M are the integers written on these boxes, in any order.

Sample Input 1

3
1 0 0

Sample Output 1

1
1

Consider putting a ball only in the box with 1 written on it.

There are three boxes with multiples of 1 written on them: the boxes with 1, 2, and 3. The total number of balls contained in these boxes is 1.

There is only one box with a multiple of 2 written on it: the box with 2. The total number of balls contained in these boxes is 0.

There is only one box with a multiple of 3 written on it: the box with 3. The total number of balls contained in these boxes is 0.

Thus, the condition is satisfied, so this set of choices is good.

Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Putting nothing in the boxes can be a good set of choices.



Sample input:
3
1 0 0


Sample output:
1
1

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n - 1, -1, -1):
    if i + 1 > n // 2:
        ans[i] = a[i]
    else:
        cnt = 0
        for j in range(i, n, i + 1):
            if ans[j] == 1:
                cnt += 1
        #ans[i] = cnt % 2 + a[i]
        if cnt % 2 == a[i]:
            ans[i] = 0
        else:
            ans[i] = 1 
#print(sum(s))
s = sum(ans)
print(s)
for i, j in enumerate(ans):
    if j == 1:
        print(i + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n, 0, -1):
    j = i
    tmp = 0
    while True:
        j += i
        if j > n:
            break
        tmp = tmp + b[j-1]
    b[i-1] = int(tmp % 2 != a[i-1])

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * N
    for i in range(N)[::-1]:
        s = sum(B[i :: i + 1]) % 2
        if A[i] == s:
            continue
        else:
            B[i] = 1

    B = [i + 1 for i in range(N) if B[i] == 1]
    print(len(B))
    print(*B, sep=" ")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    balls = [0 for _ in range(N)]
    for n in range(N, 0, -1):
        max_ratio = N // n
        if max_ratio == 1:
            balls[n - 1] = A[n - 1]
        else:
            filled_balls = sum([balls[r * n - 1] for r in range(2, max_ratio + 1)])
            balls[n - 1] = (filled_balls + A[n - 1]) % 2
    ball_cnt = sum(balls)
    print(ball_cnt)
    if ball_cnt > 0:
        ball_indices = [str(i + 1) for i in range(N) if balls[i] > 0]
        print(' '.join(ball_indices))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

i=0
b=[0]*n
while i<len(a):
    ii=n-i
    j=1
    temp=0
    while j*ii<=n:
        temp+=b[j*ii-1]
        j+=1
    if temp%2!=a[ii-1]:
        b[ii-1]=1
    else:
        b[ii-1]=0
    i+=1

result=[]
cnt=0
for index,item in enumerate(b):
    if item==1:
        cnt+=1
        result.append(str(index+1))
print(cnt)
if cnt>0:
    print(" ".join(result))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

N = int(input())
a = [0]+list(map(int, input().split()))
b = [0 for _ in range(N+1)]
for j in range(N, 0, -1):
    if j > N//2:
        b[j] = a[j]
    if sum(b[n*j] for n in range(2, (N//j)+1)) % 2 != a[j]:
        b[j] = 1

print(sum(b[1:]))
if sum(b[1:]) != 0:
    print(*[i for i, j in enumerate(b) if j == 1])

Submission status: Accepted

Solution code:
import copy

N = int(input())
a = [0]+list(map(int, input().split()))
b = copy.copy(a)
for j in range(N//2, 0, -1):
    b[j] = sum(b[j::j]) & 1
print(sum(b[1:]))
if sum(b[1:]) != 0:
    print(*[i for i, j in enumerate(b) if j == 1])

Submission status: Accepted

Solution code:
n = int(input())
box = list(map(int, input().split())) 
ans = [0]*n
lst = []
for i in reversed(range(n)):
  count = 0
  for j in range(n//(i+1)):
    count += ans[(i+1)*(j+1)-1]
  if count % 2 == box[i]:
    ans[i] = 0
  else:
    lst.append(i+1)
    ans[i] = 1
    
print(sum(ans))
print(*lst)

Submission status: Accepted

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

count = 0
B = [0]*(N+1)

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

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

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
li.reverse()
ans = [0]*n
for i,l in enumerate(li):
    j = n - i
    if n//j < 2 and l==1:
        ans[j-1] += 1
    else:
        tmp = 0
        for k in range(2,n//j+1):
            tmp += ans[j*k-1]
        if tmp%2 == 0 and l==1:
            ans[j-1] += 1
        elif tmp%2 == 1 and l == 0:
            ans[j-1] += 1
print(ans.count(1))
if ans.count(1) == 0:
    exit()
fin_li = []
for ai,a in enumerate(ans):
    if a == 1:
        fin_li.append(ai+1)
print(*fin_li)

#print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
dum_list = [0]*n
ans_list = []
for i in range(n-1,-1,-1):
    total = 0
    for j in range(i,n,i+1):
        #print(j)
        total += dum_list[j]
    if total%2 != a_list[i]:
        dum_list[i] = 1
        ans_list.append(i+1)
if sum(dum_list) == 0:
    print(0)
else:
    #print(ans_list)
    ans_list.sort()
    print(sum(dum_list))
    print(" ".join(map(str,ans_list)))

Submission status: Accepted

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

Submission status: Accepted

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

Bs = [0] * (N+1)
for i in reversed(range(1, N+1)):
    parity = sum(Bs[i::i]) % 2
    if parity != As[i-1]:
        Bs[i] = 1

anss = [i for i in range(1, N+1) if Bs[i]]

print(len(anss))
if anss:
    print(' '.join(map(str, anss)))

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0]*N
for i in range(N, 0, -1):
    cnt = 0
    j = 1
    while i*j<=N:
        cnt += ans[i*j-1]
        j += 1
    if cnt%2 != B[i-1]:
        ans[i-1] = 1

print(sum(ans))

A =[]
for i, j in enumerate(ans, 1):
    if j == 1:
        A.append(i)

print(*A)

Submission status: Accepted

Solution code:
N, *a = map(int, open(0).read().split())
for i in range(N)[::-1]:
    part_rem = sum(a[i::i+1]) % 2
    if a[i] != part_rem:
        a[i] = 1 - a[i]
        
print(sum(a))
print(*[i+1 for i, v in enumerate(a) if v == 1])

Submission status: Accepted

Solution code:
N,*a = map(int,open(0).read().split())
for i in range(N)[::-1]:
    part_rem = sum(a[i::i+1]) % 2
    if a[i] != part_rem:
        a[i] = abs(a[i] - 1) 

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

Submission status: Accepted

Solution code:
N,*a = map(int,open(0).read().split())
ans = []
for i in range(N)[::-1]:
    part_rem = sum(a[i::i+1]) % 2
    if a[i] != part_rem:
        a[i] = abs(a[i] - 1) 

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

Submission status: Accepted

Solution code:
from collections import Counter

N,*a = map(int,open(0).read().split())
ans = []
for i in range(N)[::-1]:
    part_rem = sum(a[i::i+1]) % 2
    if a[i] == 0:
        if part_rem == 1:
            a[i] = abs(a[i] - 1) 
    elif a[i] == 1:
        if part_rem == 0:
            a[i] = abs(a[i] - 1)
            
c = Counter(a)            
print(c[1])
for i in range(N):
    if a[i] == 1:
        print(i+1,end=" ")
print()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(lambda x:int(x)%2,input().split()))
ans=[0]*n
for i in range(n,0,-1):
    b=n//i
    c=0
    for j in range(1,b+1):
        c+=ans[j*i-1]
    if (c-a[i-1])%2==1:
        ans[i-1]=1

print(sum(ans))
ans1=[]
for i,v in enumerate(ans):
    if v==1:
       ans1.append(i+1)
if len(ans1)>0:
    print(' '.join(map(str,ans1)))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
box = [0 for _ in range(N + 1)]
ans = []
for i in range(1, N + 1)[:: -1]:
    k = 1
    my_sum = 0
    while i * k <= N: 
        my_sum += box[i * k]
        k += 1
    if my_sum % 2 != a[i - 1]:
        box[i] = 1
        ans.append(i)
if len(ans) > 0:
    print(len(ans))
    print(" ".join(map(str, ans)))
else:
    print(0)

Submission status: Accepted

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

b = [0]*N
ans = []
for i in range(N, 0, -1):
  if b[i-1] % 2 != a[i-1]:
    ans += [i]
    if i == 1:
      b[i-1] += 1
      b[i-1] %= 2
      continue
    for j in range(1, math.floor(math.sqrt(i))+1):
      if i % j == 0:
        b[j-1] += 1
        b[j-1] %= 2
        if i//j != j and i//j-1 <= N-1:
          b[i//j-1] += 1
          b[i//j-1] %= 2

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
e=0
dic={}
for i in range(N):
 d=0
 B=int(N/(N-i))
 if B==1 and A[N-i-1]==1:
   dic[N-i]=1
   e+=1
 elif B>1:
  for k in range(1,B+1):
   if (k+1)*(N-i) in dic:
    d+=1
  if (d+A[N-i-1])%2==1:
   dic[N-i]=0
   e+=1
if dic=={}:
 print(0)
else:
 print(e)
 b = dic.keys()
 z=[str(a) for a in b]
 z=' '.join(z)
 print(z)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    A = [0] + A
    b = A[:]
    n = N // 2 + 1
    m = sum(b[n:])
    for i in range(n - 1, 0, -1):
        sum_ = sum([b[j] for j in range(i, N + 1, i)])
        if A[i] != sum_ % 2:
            b[i] = (b[i] + 1) % 2
        m += b[i]

    print(m)
    if m:
        print(*[i for i, v in enumerate(b) if v])


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
idx = lambda x: x-1
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
for i in reversed(range(1, n+1)):
    cnt = 0
    for j in range(i*2, n+1, i):
        cnt += b[idx(j)]
    if cnt % 2 == a[idx(i)]: continue
    b[idx(i)] += 1
s = sum(b)
if s == 0:
    print(0)
    exit()
print(s)
for i in range(1, n+1):
    if b[idx(i)]: print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
ball=[-1]*N
for i in range(N-1,-1,-1):
    n=0
    for j in range(i,N,i+1):
        if ball[j]==1:
            n=n+1
        #print(i,j,ball)
        #input()
    bali=(n+a[i])%2
    #print(bali)
    ball[i]=bali
#print(ball)
ballnum=sum(ball)
balls=[]
print(ballnum)
for i in range(N):
    if ball[i]==1:
        balls.append(i+1)
if len(balls)>0:
    print(*balls,sep=" ")

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0] * n
    for i in range(n - 1, -1, -1):
        if (sum(ans[i::i + 1]) % 2) == a[i]:
            ans[i] = 0
        else:
            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())
alist=[0]+list(map(int,input().split()))
#print(alist)

blist=[0]*(N+1)
for i in reversed(range(1,N+1)):
  blist[i]=alist[i]
  for j in range(2*i,N+1,i):
    blist[i]+=blist[j]
  blist[i]%=2
  
#print(blist[1:])
answer_list=[i for i in range(1,N+1) if blist[i]==1]
print(len(answer_list))
print(*answer_list)

Submission status: Accepted

Solution code:
N, a = int(input()), list(map(int, input().split()))
result = [0] * N
for i in range(N//2, N):
    result[i] = a[i]
for i in range(N//2, -1, -1):
    temp = N // (i+1)
    work = 0
    for j in range(1, temp+1): work += result[(i+1) * j - 1]
    if work % 2 != a[i]: result[i] = 1
i = 1
print(result.count(1))
for r in result:
    if r == 1:print(i)
    i += 1

Submission status: Accepted

Solution code:
# D - Preparing Boxes

n = int(input())
a = list(int(x) for x in input().split())

ans = [0] * n

for i in range(n)[::-1]:
    tmp = 0
    j = 0
    while i+(i+1)*j<n:
        tmp += ans[i+(i+1)*j]
        j += 1
    if tmp%2==a[i]:
        continue
    else:
        ans[i] = 1

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

Submission status: Accepted

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

b = []
c = [0 for i in range(n+1)]

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

print(len(b))
print(" ".join(list(map(str, b))))

Submission status: Accepted

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

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

print(sum(ball))
if sum(ball)!=0:
  b=[]
  for i in range(N):
    if ball[i]==1:
      b.append(i+1)
  print(*b)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc134/submissions/7469219

def main():
    N = int(input())

    a = [0]
    a += map(int, input().split())

    for x in reversed(range(1, N // 2 + 1)):
        a[x] = sum(a[x::x]) & 1

    ans = [i for i, x in enumerate(a) if x]
    print(len(ans))
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc134/submissions/7469219

def main():
    from functools import reduce
    from operator import xor

    N = int(input())

    a = [0]
    a += map(int, input().split())

    for x in reversed(range(1, N // 2 + 1)):
        a[x] = reduce(xor, a[x::x])

    ans = [i for i, x in enumerate(a) if x]
    print(len(ans))
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Accepted

Solution code:
def main():
    N = int(input())

    a = [0]
    a += map(int, input().split())

    b = [0] * (N + 1)

    x = N
    k = 1
    while x > 0:
        while x * (k + 1) > N:
            t = 0
            for j in range(2, k + 1):
                t ^= b[x * j]
            b[x] = a[x] ^ t
            x -= 1
        k += 1

    ans = [i for i, x in enumerate(b) if x == 1]
    print(len(ans))
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Accepted

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

n=int(input())
a=list(map(int,input().split()))
b=[0]*n
if n==1:
    b=a
elif n==2:
    b[1]=a[1]
    b[0]=(a[0]-b[1])%2
    
elif n==3:
    b[1]=a[1]
    b[2]=a[2]
    b[0]=(a[0]-b[1]-b[2])%2
else:
  i=2
  while n/i>=1:
      for k in range((n//i)+1,n//(i-1)+1):
          j=2
          b[k-1]=a[k-1]
          while j*k-1<n:
              b[k-1]=(b[k-1]-b[j*k-1])%2
              j+=1
      i+=1
  j=1
  b[0]=a[0]
  while j*1<n:
      b[0]=(b[0]-b[j*1])%2
      j+=1
num=sum(b)
print(num)
for i in range(n):
    if b[i]==1:
        print(i+1)

Submission status: Accepted

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

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

print(sum(ans))
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()))
FB = [0 for _ in range(N//2)]
SB = A[N//2:N]
B = FB + SB
S = [i for i in range(1,N//2+1)]
FH = A[0:N//2]
for i in range(1,len(FH)+1):
    s = 0
    for j in range(2,N//S[-i]+1):
        s += B[S[-i]*j-1]
    if N % 2 == 0:
        if s % 2 != FH[-i]:
            B[-i-N//2] = 1
    else:
        if s % 2 != FH[-i]:
            B[-i-N//2-1] = 1            
ans = []
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())
a = [int(x) for x in input().split()]
ans = [0]*n

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

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

Submission status: Accepted

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

b = [0 for _ in range(n)]


def check(i, n):
    cnt = 0
    t = i
    while t <= n:
        cnt += b[t-1]
        t += i
    return cnt


for i in range(n-1, -1, -1):
    if (a[i] + check(i+1, n)) % 2 == 1:
        b[i] = 1

ans = []
cnt = 0
for i in range(n):
    if b[i] == 1:
        cnt += 1
        ans.append(i+1)
print(cnt)
l = [str(int(i)) for i in ans]
print(' '.join(l))

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
b_list = [0 for i in range(n)]
for i in range(n,0,-1):
  num = n//i
  if num >= 2 :
    check = 0
    for _ in range(1,num+1):
       check += b_list[_ * i - 1] % 2
    if check % 2 == 1:
      if a_list[i-1] == 0:
        b_list[i-1] = 1
      else:
        b_list[i-1] = 0
    else:
      if a_list[i-1] == 0:
        b_list[i-1] = 0
      else:
        b_list[i-1] = 1

  if num == 1:
    b_list[i-1] = a_list[i - 1]

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

Submission status: Accepted

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

temp_list = [False] * (n + 1)
for i in range(n, 0, -1):
    count = 0
    for j in range(i * 2, n + 1, i):
        if temp_list[j]:
            count += 1

    if count % 2 != a_list[i]:
        temp_list[i] = True

ans_list = [i for i in range(n + 1) if temp_list[i]]
print(len(ans_list))
for ans in ans_list:
    print(ans, end=" ")

Submission status: Accepted

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

l = [0 for i in range(n+1)]
for i in range(n, 0, -1):
    if i > n//2 and a[i-1] == 1:
        l[i] = 1
    elif i <= n//2:
        tmp = 2
        cnt = 0
        while tmp*i <= n:
            cnt += l[tmp*i]
            tmp += 1
        if cnt%2 != a[i-1]:
            l[i] = 1
l2 = []
for i in range(len(l)):
    if l[i] == 1:
        l2.append(i)
print(len(l2))
print(" ".join(map(str, l2)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
ans = [a[n-1]]
if n == 1:
  print(a[0])
  if a[0] == 1:
    print(1)
  exit()
  
for i in range(n-2,-1,-1):
  if i+1 > n//2:
    ans.append(a[i])
  else:
    ans.append((sum(ans[n%(i+1)::(i+1)])-a[i])%2)
    
print(sum(ans))
chk = []
for i,ai in enumerate(ans):
  if ai == 1:
    chk.append(n-i)
print(*chk)

Submission status: Accepted

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

for i in range(n - 1, -1, -1):
    cnt = 0
    for j in range(i, n, i + 1):
        if i == j:
            continue
        else:
            if b[j] == 1:
                cnt += 1
    if (A[i] + cnt) % 2 == 0:
        b[i] = 0
    else:
        b[i] = 1
        ans.append(i + 1)

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


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


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


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc134/tasks/abc134_d
# 偶奇だけが重要
# 後半は即座に決定できる(倍数が存在しないので)
# 後ろから決定できない？
# nの倍数の個数を更新していく

N = read_a_int()
A = read_ints()

ans = [0] * N
ans[N // 2:] = A[N // 2:]
for i in ra(N // 2 - 1, -1, -1):
    # (i+1)の倍数の個数の集計
    n = i + 1
    s = sum(ans[i::n]) % 2
    ans[i] = s ^ A[i]

print(sum(ans))
ans_pr = []
for i, v in enu(ans, start=1):
    if v:
        ans_pr.append(i)
print(*ans_pr)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations
from math import pi, ceil, floor
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")



def main():
    n = int(input())
    A = list(map(int, input().split()))
    cnt = [0] * n
    B = deque([])
    for i in range(n-1, -1, -1):
        if sum(cnt[i::i+1]) % 2 == A[i]:
            continue
        else:
            cnt[i] += 1
    ans = []
    for i, v in enumerate(cnt):
        if v > 1:
            print(-1)
            exit()
        elif v == 1:
            ans.append(i+1)
        else:
            continue
    print(len(ans))
    print(*ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a =[2] + list(map(int,input().split()))

b = [3]*(n+1)

for i in range(n,n//2,-1):
    if a[i] == 1:
        b[i] = 1
    else:
        b[i] = 0
#print(b)
for i in range(n//2,0,-1):
    isum = 0
    for k in range(2,n//i+1):
        isum += b[i*k]
    #print(isum)
    if a[i] == isum%2:
        b[i] = 0
    else:
        b[i] = 1
ans = []

for i in range(1,len(b)):
    if b[i] == 1:
        ans.append(i)
print(sum(b)-3)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
ball=[0]*N
for i in range(N-1,-1,-1):
    #i+1>=N//2+1
    if i>=N//2:
        ball[i]=A[i]
    else:
        now=0
        n=2
        while (i+1)*n-1<N:
            now+=ball[(i+1)*n-1]
            n+=1
        if now%2!=A[i]:
            ball[i]=1
print(sum(ball))
for i,b in enumerate(ball):
    if b!=0:
        print(i+1, end=" ")

Submission status: Accepted

Solution code:
def divisors(n):
    ret = set()
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            ret.add(i)
            ret.add(n//i)
    return(ret)


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

    ans = set()
    for i in range(N-1, -1, -1):
        a[i] %= 2
        # print(a)
        if a[i]:

            for j in divisors(i+1):
                # print(j-1)
                a[j-1] += 1
            ans.add(i+1)

    print(len(ans))

    print(*ans)


main()

Submission status: Accepted

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

for i in range(n-1,-1,-1):
    now = i+1
    if a[i] == 0:
        if sum(box[i+now::now])%2 == 1:
            box[i] = 1
            box_list.append(i)
    else:
        if sum(box[i+now::now])%2 == 0:
            box[i] = 1
            box_list.append(i)

print(len(box_list))
for i in box_list:
    print(i+1)

Submission status: Accepted

Solution code:
def resolve():
    import math
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0] * n
    ans[math.floor(n/2):n] = a[math.floor(n/2):n]
    if n == 1 and a[0] == 1:
        print(1)
        print(1)
    else:
        for i in range(math.floor(n/2)-1, 0, -1):
            sumi = 0
            for j in range(i, n, i+1):
                sumi += ans[j]
                sumi %= 2
            if sumi == a[i]:
                ans[i] = 0
            else:
                ans[i] = 1
        if a[0] == sum(ans)%2:
            ans[0] = 0
        else:
            ans[0] = 1
        ansl = []
        for i, j in enumerate(ans):
            if j == 1:
                ansl.append(i+1)
        print(len(ansl))
        if len(ansl)!= 0:
            print(" ".join(map(str, ansl)))
resolve()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
B = [0] * N # 入っている箱 0 1 0 1とか
wa = 0
tmp = 0
for i in range(N, 0, -1):
    tmp = 0
    for j in range(i, N+1, i):
        if i == j:
            continue
        else:
            # print(j)
            tmp ^= B[j-1]
    # print("*****")
    if tmp == A[i-1]:
        B[i-1] = 0
    else:
        B[i-1] = 1
# print(B)
M = sum(B)
if M == 0:
    print(M)
    exit()
else:
    print(M)
    for i, b in enumerate(B):
        if b == 1:
            print(i+1, end=" ")
    print()

Submission status: Accepted

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