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())
array = [int(x) for x in input().split()]
ans = [0 for x in range(n)]
res = []
count = 0
for i in reversed(range(n)):
    a = array[i]
    if a == 1 and sum([x for x in ans[i::i+1]]) % 2 == 0:
        ans[i] = 1
        count += 1
        res.append(str(i+1))
    elif a == 0 and sum([x for x in ans[i::i+1]]) % 2 == 1:
        ans[i] = 1
        count += 1
        res.append(str(i+1))
print(count)
print(" ".join(res))

Submission status: Accepted

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

for i in range(N-1,-1,-1):
  rest = 0
  for j in range(2 * (i+1),N+1,i+1):
    rest += box[j-1]
  box[i] = (b[i] - rest)%2
print(sum(box))
if sum(box):
  for idx,i in enumerate(box):
    if i == 1:
      print(idx+1)

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = [0] + lr()
# 後ろから決める、愚直にやって計算時間はNlogN
for i in range(N, 0, -1):
    result = sum(A[i::i]) % 2
    if A[i] != result:
        A[i] = 1 - A[i]

print(sum(A))
print(*[i for i, x in enumerate(A) if x])

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

b[-1] = a[-1]
for i in reversed(range(N+1)):
    sum = 0
    for j in range(2, N+1):
        if i*j <= N:
            sum += b[i*j]
        else:
            break
    if sum%2 == a[i]:
        b[i] = 0
    else:
        b[i] = 1

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array([0] + lr())
for i in range(N//2, 0, -1):
    a = A[i]
    result = A[i::i].sum()
    if result % 2 != a:
        A[i] = 1 - a

B = np.where(A == 1)[0]
print(len(B))
print(*B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = [0] * n
for itr, val in enumerate(A[::-1]):
  idx = n - itr
  if sum([ans[(i + 1) * idx - 1] for i in range(n // idx)]) % 2 != val:
    ans[idx - 1] = int(not ans[idx - 1])

# print(ans)
    
p = sum(ans)
print(p)    

if p > 0:
  print(*[i + 1 for i, j in enumerate(ans) if j == 1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

count = [0 for _ in range(n)]
for i in reversed(range(1, n + 1)):
    tmp = 0
    for j in range(i, n+1, i):
        tmp += count[j-1]
    #print(tmp)
    if a[i-1] % 2 != tmp % 2:
        count[i-1] += 1
#print(count)
m = sum(count)
ans = []
for i in range(n):
    if count[i] == 1:
        ans.append(str(i+1))

print(m)
print(' '.join(ans))

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 fractions import gcd
 
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()
#ball
X = [0] * (N + 1)
for i in range(N, 0, -1):
    # num = i+1
    tmp = A[i-1]
    # ここから上のボール
    for j in range(i, N+1, i):
        #これなかった
        if j == i:
            continue
        # AではなくボールXと
        # tmp ^= A[j-1]
        tmp ^= X[j]
    # X[i] = tmp ^ A[i]
    X[i] = tmp
    
    # if tmp == 0:
    #     X[i] = 0
    # else:
    #     X[i] = 1
# print(X)
# if sum(X) == 0:
#     print(sum(X))
#     exit()
print(sum(X))
ans = []
for i in range(N):
    if X[i+1] == 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 reversed(range(n)):
    j = i+1
    cnt = 0
    while j <= n:
        cnt += B[j-1]
        j += i+1
    if cnt%2 != A[i]:
        B[i] = 1

m = 0
ans = []
for i, b in enumerate(B):
    if b != 0:
        m += 1
        ans.append(i+1)
print(m)
if len(ans) > 0:
    print(*ans)

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())

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

memo = [0 for _ in range(N+1)]

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

    while idx <= N:
        tmp_s += memo[idx]
        idx += i

    memo[i] = (tmp_s % 2) ^ a[i-1]

ret = [i for i in range(1,N+1) if memo[i] == 1]
if len(ret) == 0:
    print(0)
else:
    print(len(ret))
    ret = list(map(str,ret))
    print(' '.join(ret))

Submission status: Accepted

Solution code:
import math
N = int(input())
a = list(map(int,input().split()))
b = [0]*N
ans = []
for k in range(N,0,-1):
    if a[k-1]%2 != b[k-1]%2:
        ans.append(k)
        b[0] += 1
        b[k-1] += 1
        for l in range(2,math.floor(math.sqrt(k))+1):
            if k % l == 0:
                if l*l == k:
                    b[l-1] += 1
                else:
                    b[l-1] += 1
                    b[k//l-1] += 1
print(len(ans))
if len(ans) > 0:
    print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ind = list(range(1, N+1))


B = [0] * (N + 1)
for i in reversed(range(1, N + 1)):
    if i > N // 2:
        B[i] = A[i - 1]
        continue

    cnt = 0
    x = i * 2
    while x <= N:
        cnt += B[x]
        x += i
    cnt %= 2
    B[i] = cnt ^ A[i - 1]


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

Submission status: Accepted

Solution code:
import sys

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

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    Count = [0] * N
    In = []
    add = 0
    for i in reversed(range(N)):
        if Count[i] % 2 == A[i]: continue
        elif (Count[i] + 1) % 2 == A[i]:
            add += 1
            In.append(i + 1)
            D = div(i + 1)
            for d in D: Count[d - 1] += 1
        else:
            print(-1)
            break
    else:
        print(add)
        print(" ".join(map(str, In)))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

    box = [0] * N
    for i in range(N - 1, -1, -1):
        # ボールの総数
        cnt = 0
        # (i + 1)の倍数
        num = i + 1
        while num <= N:
            cnt += box[num - 1]
            num += (i + 1)
        
        if cnt % 2 != A[i]:
            box[i] = 1

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

    print(len(ans))
    if ans:
        print(*ans, sep=" ")

if __name__ == "__main__":
    main()

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, acos, atan, asin
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 fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
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 = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
b = [0 for _ in range(n)]
for i in reversed(range(n)):
    if i * 2 >= n:
        b[i] = a[i]
        continue
    s = 0
    for j in range(i, n, i + 1):
        s += b[j]
    if s % 2 != a[i]:
        b[i] = 1
print(sum(b))
for i in range(n):
    if b[i] == 1:
        print(i + 1, end=' ')
print('')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()]
    C = [0]*(N+1)
    for i in range(1, N+1)[::-1]:
        cur = 0
        for j in range(i, N+1, i):
            cur += C[j]
        if cur % 2 != A[i] % 2:
            C[i] += 1
    M = sum(C)
    print(M)
    if M:
        C = [i for i in range(1, N+1) if C[i]]
        print(*C)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

box = [0]*(N+1)
ans = []
for n in range(N,0,-1):
    c = 0
    for i in range(n,N+1,n):
        c += box[i]
    c %= 2
    if A[n-1] != c:
        box[n] = 1
        ans.append(n)
print(len(ans))
if ans:
    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]:
    a = A[i]
    cnt = 0
    for j in range(i, N, (i + 1)):
        cnt += ans[j]
    if cnt % 2 != a % 2:
        ans[i] = 1

M = sum(ans)
print(M)
if M > 0:
    print(*[i for i, a in enumerate(ans, start=1) if a > 0])

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + [int(s) for s in input().split(' ')]

B = [0] * (N + 1)
count = 0
ret = []
for i in range(N, 0, -1):
    ai = A[i]
    ii = i
    total = 0
    while ii <= N:
        total += B[ii]
        ii += i
    
    if total % 2 == ai:
        continue
    else:
        B[i] = 1
        count += 1
        ret.append(i)

print(count)
print(' '.join(str(i) for i in ret))

Submission status: Accepted

Solution code:
# correct_case
# 6     1 2 3 4 5 6
# aaa = 1 1 0 1 1 1
# bbb = x x x x x 1 | k / 2まではa[i] と同じ
# bbb = x x x x 1 1 | k / 2まではa[i] と同じ
# bbb = x x x 1 1 1 | k / 2まではa[i] と同じ
# bbb = x 1 1 1 1 1 | sum_b[6] % 2 == 1 で != 0(a[1]) なので 1
# bbb = 0 1 1 1 1 1 | sum_b[2,3,4,5,6] % 2 = 1 で == 1(a[0]) なので 0

n = int(input())
aaa = list(map(int, input().split(' ')))
aaa = [0] + aaa
bbb = [0] * len(aaa)
ans_count = 0
ans = []
for i in range(n, 0, -1):
    hoge = 0
    for j in range(i+i, n+1, i):  # !!!!!!
        hoge += bbb[j]
    bbb[i] = 0 if (hoge % 2) == aaa[i] else 1
    if bbb[i] == 1:
        ans_count += 1
        ans.append(i)
    
print(ans_count)
if ans:
    print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=[0]*(n+1)
    m=0
    for i in range(n,0,-1):
        k=n//i
        if k==1:
            b[i]=a[i-1]
        else:
            s=0
            for j in range(2,k+1):
                s+=b[i*j]
            b[i]=(s+a[i-1])%2
    ans=[]
    for i in range(1,n+1):
        if b[i]==1:
            ans.append(i)
    print(sum(b))
    if len(ans)!=0:
        print(' '.join(map(str,ans)))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
alist = list(map(int, input().split()))
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors

balls_multiple = [0] * N
ans = []
for num in range(N-1, -1, -1):
    if balls_multiple[num] % 2 != alist[num]:
        ans.append(num+1)
        for div in make_divisors(num+1):
            balls_multiple[div-1] += 1
if ans:
    print(len(ans))
    print(*sorted(ans))
else:
    print(0)

Submission status: Accepted

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

ans = [0 for _ in range(N+1)]
for i in reversed(range(1,N+1)) :
    temp = 0
    for j in range(N//i) :
        temp += ans[(j+1) * i]
    if temp%2 != a[i] :
        ans[i] = 1

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = [0]*N
bina = 0
M = 0
for i in reversed(range(1,N+1)):
    next_num = i+i
    while(next_num <= N):
        bina ^= b[next_num-1]
        next_num += i
    b[i-1] = bina^a[i-1]
    bina = 0
M = sum(b)
print(M)
for i in range(N):
    if(b[i] == 1):
        print(i+1)

Submission status: Accepted

Solution code:
#約数
def divisor(x):
    ret = []
    for i in range(1,int(x ** 0.5) + 1):
        if x % i == 0:
            ret.append(i)
            if i != x // i:
                ret.append(x // i)
    return ret

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

ans = []
d = [0] * n

for i in range(len(a) - 1,-1,-1):
    if d[i] % 2 != a[i]:
        ans.append(i + 1)
        for j in divisor(i + 1):
            d[j - 1]+=1

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

Submission status: Accepted

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


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


divisor = []
for i in range(1, N + 1):
    divisor.append(make_divisors(i))
B = [0]*N
rs = [0]*N
for i in range(N - 1, -1, -1):
    if rs[i] != A[i]:
        B[i] = 1
        for j in divisor[i]:
            rs[j-1] = 1 - rs[j-1]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
D - Preparing Boxes
https://atcoder.jp/contests/abc134/tasks/abc134_d

"""
import sys


def solve(N, arr):
    res = [0] * (N//2) + arr[N//2:]
    for i in range(N//2, 0, -1):
        t = res[i-1::i]
        s = sum(t)
        res[i-1] = 1 if (s + 1) % 2 == arr[i-1] else 0
    #print(res)
    return sum(res), [i for i, a in enumerate(res, start=1) if a]


def main(args):
    N = int(input())
    arr = [int(i) for i in input().split()]
    M, balls = solve(N, arr)
    print(M)
    if M:
        print(*balls)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
#python3

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    b = [0 for _ in range(n)]
    for i in reversed(range(1, n+1)):
        s = 0
        j = i + i
        while j <= n: 
            s ^= b[j-1]
            j += i
        b[i-1] = s^a[i-1]
    
    m = sum(b)
    print(m)
    for i in range(n):
        if b[i] == 1:
            if i == n-1:
                print(i+1)
            else:
                print(i+1, end=' ')
        
main()

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    ball = [0] * (n+1)

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

    res = []
    m = 0

    for i in range(1, n+1):
        if ball[i] == 1:
            res.append(i)
            m+=1
    if m > 0:
        print(m)
        print(*res)
    else:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# D
n = int(input())
a = list(map(int, input().split()))
ans = [0 for i in range(n+1)]
a.reverse()
for i,num in enumerate(a):
    sum_a = 0
    for j in range(0, n+1, (n-i)):
        sum_a += ans[j]
    if sum_a%2 == 0:
        if num == 1:
            ans[n-i] = 1
    else:
        if num == 0:
            ans[n-i] = 1
sum_ans = 0
ansprint = []
for i,num in enumerate(ans):
    if num == 1:
        ansprint.append(i)
        sum_ans+=1
print(sum_ans)
print(*ansprint, sep=' ')

Submission status: Accepted

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

for i in range(1,N+1)[::-1]:
    s = 0
    now = 0
    k = 2

    while True:
        now = i*k
        if now > N:
            break
        s += ball[now]
        k += 1

    if s%2 == a[i]:
        ball[i] = 0
    else:
        ball[i] = 1

print(sum(ball))

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
for i in range(N,0,-1):
  s = A[i-1]
  k = i*2
  while k<=N:
    s ^= B[k-1]
    k += i
  if s==1:
    B[i-1] = s
if sum(B)==0:
  print(0)
else:
  print(sum(B))
  for i in range(N):
    if B[i]==1:
      print(i+1,end=' ')

Submission status: Accepted

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

cnt = [0]*n
for i in range(n,0,-1):
  total = sum(cnt[i*k-1] for k in range(1,n//i+1))
  if total % 2 != a[i-1]:
    cnt[i-1] = 1

b = [i+1 for i in range(n) if cnt[i] > 0]

print(sum(cnt))
print(*b)

Submission status: Accepted

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

for i in range(n,0,-1):
    
    k = 1
    count = 0
    while k*i <= n:
        count += ans[k*i]
        k += 1
    if count%2 != l[i-1]:
        ans[i] = 1
print(sum(ans))
if sum(ans) > 0:
    for i in range(n+1):
        if ans[i] == 1:
            print(i,end=" ")

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 i > n / 2:
        if a[i - 1] == 1:
            b[i - 1] = 1
    else:
        j = 2 * i
        c = 0
        while True:
            if j > n:
                break
            c += b[j - 1]
            j += i
        if (a[i - 1] + c) % 2 != 0:
            b[i - 1] = 1
ans = []
m = 0
for i in range(n):
    if b[i] == 1:
        ans.append(i + 1)
        m += 1
print(m)
if len(ans) != 0:
    print(" ".join(map(str, ans)))

Submission status: Accepted

Solution code:
from collections import deque

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

check = [0] * N

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

M = sum(check)
ans = deque()

for index, value in enumerate(check):
    if value == 1:
        ans.append(index + 1)

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

Submission status: Accepted

Solution code:
from collections import deque

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

check = [0] * N

for i in reversed(range(1, N + 1)):
    x = i
    total = 0
    while x <= N:
        total += check[x - 1]
        x += i
    if total % 2 != A[i - 1]:
        check[i - 1] = 1

M = sum(check)
ans = deque()

for index, value in enumerate(check):
    if value == 1:
        ans.append(index + 1)

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

Submission status: Accepted

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

#    print(i, list(range(2 * i, n+1, i)))

    #for j in range(2 * i, n+1, i):

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())

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

for i in reversed(range(n)):
    if a[i] > 1:
        print(-1)
        exit()
    cnt = n // (i+1)
    tmp = 0
    for j in range(2,cnt+1):
        tmp += c[(i+1) * j-1]
    tmp2 = (tmp%2+a[i])%2
    c[i] = tmp2
    ans += tmp2
    if tmp2 == 1:
        b.append(i+1)
b.sort()
print(ans)
print(*b, sep=' ')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
jud = [0] * n
ans = []
for i in range(n//2, n):
    if a[i] == 1:
        jud[i] = 1
        ans.append(i+1)
for i in range(n//2-1, -1, -1):
    cou = 0
    for j in range(2, n//(i+1)+1):
        cou ^= jud[(i+1)*j-1]
    if a[i] != cou:
        jud[i] = 1
        ans.append(i+1)
ans.sort()
print(jud.count(1))
print(*ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
MOD = 10**9+7

N = int(inp())
A = [0] + list(map(int, inp().split()))

# A[i]余りが1: sum(A[i::i])が奇数
for i in range(N//2, 0, -1):
  A[i] = sum(A[i::i])&1
  
ans = [i for i, a in enumerate(A) if a]  

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

for i in reversed(range(1,n+1)):
    if sum(A[::i])%2!=A[i]:
        if A[i]==0:
            A[i]=1
        else:
            A[i]=0
        
print(sum(A))
if sum(A)!=0:
    for i,a in enumerate(A):
        if a==1:
            print(i)

Submission status: Accepted

Solution code:
n=int(input())

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

for i in reversed(range(1,n+1)):
    if sum(A[::i])%2!=A[i]:
        A[i]^=1
        
print(sum(A))
if sum(A)!=0:
    for i,a in enumerate(A):
        if a==1:
            print(i)

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())

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

x=[]

for i in range(n//2,n):
    if A[i]==1:
        x.append(i+1)

x=deque(x)



for i in reversed(range(0,n//2)):
    A[i]=A[i]*2-sum(A[i::i+1])
    A[i]%=2
    if A[i]==1:
        x.appendleft(i+1)
        
print(len(x))
if len(x)!=0:
    print(*x)

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 fractions import gcd
 
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()
# ball を入れたら1
ball = [0] * (N+1)
for i in range(N, 0, -1):
    tmp = A[i-1]
    for j in range(i, N+1, i):
        if j == i:
            continue
        tmp ^= ball[j]
    # 辻褄合わせるためにはこれが必要
    ball[i] = tmp
print(sum(ball))
for i, b in enumerate(ball):
    if b == 1:
        print(i, end=" ")

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(rem))

if sum(rem):
    ans = []
    for i, ele in enumerate(rem):
        if ele:
            ans.append(i)
    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(0,N):
    x=N-i
    cnt=0
    for j in range(0, N//x):
        if b[x*(j+1)-1]==1:
            cnt+=1
    b[x-1]=(cnt-a[x-1])%2
print(sum(b))
for i in range(N):
    if b[i]:
        print(i+1)

Submission status: Accepted

Solution code:
#134_D
n=int(input())
a=[0]+list(map(int,input().split()))
b=[0 for _ in range(n+1)]
for i in range(n,0,-1):
    if i>n//2:
        b[i]=a[i]
    else:
        b[i]=int(sum([b[k] for k in range(i*2,n+1,i)])%2!=a[i])
print(sum(b))
if sum(b)>0:
    ans=[]
    for i in range(1,n+1):
        if b[i]==1:
            ans.append(i)
    print(*ans)

Submission status: Accepted

Solution code:
def main():
    box = int(input())
    target = [0] + list(map(int, input().split()))
    balls = [0] * (box + 1)
    put = []
    for i in range(box, 1, -1):
        if not sum(balls[i::i]) % 2 == target[i]:
            balls[i] = 1
            put.append(str(i))
    all_balls = sum(balls)
    if not all_balls % 2 == target[1]:
        put.append("1")
        all_balls += 1
    print(all_balls)
    print(" ".join(put))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [0]*N
    for i in range(N)[::-1]:
        cur_sum = -B[i]
        for j in range(i, N, i+1):
            cur_sum += B[j]
        if cur_sum % 2 != A[i] % 2:
            B[i] = 1
    # print(B)
    ans = [i+1 for i, b in enumerate(B) if b]
    print(len(ans))
    if ans:
        print(*ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# Problem D - Preparing Boxes

# input and initialization
N = int(input())
a_list = list(map(int, input().split()))
current_num = [0]*N

M = 0
b_list = []
is_equivalent = True

for i in reversed(range(1,N+1)):
    num = 1
    for j in range(i,N+1,i):
        if current_num[j-1]==1:
            num = num + 1
    if num%2==a_list[i-1]:
        current_num[i-1] = 1

for i in range(N):
    if current_num[i]>=1:
        M = M + 1
        b_list.append(i+1)

# output process
print(M)
for b in b_list:
    print(b, end=" ")

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())

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

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

Submission status: Accepted

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

box = [0] * n
ans = []

cnt = 0
for itr, val in enumerate(A[::-1]):
  idx = n - itr -1
  sums_mod2 = sum(box[idx::idx+1]) % 2
  if val != sums_mod2:
    box[idx] += 1
    cnt += 1
    ans.append(idx + 1)
    
print(cnt)
print(*ans)

Submission status: Accepted

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

check = [0] * (n+1)
res = []

for i in range(n,0,-1):
    if sum(check[2*i::i])%2 == a[i]:
        continue
    else:
        check[i] = 1
        res.append(i)
print(len(res))
print(*res)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

    divisors.sort()
    return divisors
res = []
for i in range(n,0,-1):
    if a[i-1]:
        res.append(i)
        for j in make_divisors(i):
            a[j-1] ^= 1
print(len(res))
if len(res) > 0:
    print(*res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0] * (n + 1)
# 後ろからボールの有無を決定
for i in range(n, 0, -1):
    cnt = sum(b[::i])
    # 条件と異なるならボールを投入
    if cnt % 2 != a[i - 1]:
        b[i] = 1
m = sum(b)
print(m)
for i in range(1, n + 1):
    if b[i]:
        print(i, end=' ')

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):
    cnt = 0
    for j in range(2 * (i + 1), n + 1, i + 1):
        cnt += b[j - 1]
    # 条件と異なるならボールを投入
    if cnt % 2 != a[i]:
        b[i] = 1
m = b.count(1)
print(m)
for i in range(n):
    if b[i]:
        print(i + 1, end=' ')

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):
    cnt = 0
    for j in range(2 * (i + 1), n + 1, i + 1):
        cnt += b[j - 1]
    if cnt % 2 != a[i]:
        b[i] = 1
m = b.count(1)
print(m)
for i in range(n):
    if b[i]:
        print(i + 1, end=' ')