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:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def count(k, bins, N):
    current = 0
    for i in range(2, N+1):
        if k * i <=N:
            if bins[k*i] == -1:raise ValueError(f'bins{i} is not filled yet')
            current += bins[k*i]
        else:
            break
    return current % 2

def run():
    N = int(sysread())
    A = list(map(int, sysread().split()))
    A = [-1] + A
    bins = [-1] * (N+1)

    for i in range(N, 0, -1):
        bins[i] = (A[i] - count(i, bins, N)) % 2


    print(sum(bins) + 1)
    ans = []
    for i, b in enumerate(bins):
        if b == 1:
            ans.append(str(i))
    print(' '.join(ans))


if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def count(k, bins, N):
    current = 0
    for i in range(2, N+1):
        if k * i <=N:
            if bins[k*i] == -1:raise ValueError(f'bins{i} is not filled yet')
            current += bins[k*i]
        else:
            break
    return current % 2

def check(bins):
    for b in bins[1:]:
        if b == -1:
            return False
    return True

def run():
    N = int(sysread())
    A = list(map(int, sysread().split()))
    A = [-1] + A
    bins = [-1] * (N+1)

    for i in range(N, 0, -1):
        tmp =(A[i] - count(i, bins, N)) % 2
        if bins[i] == -1 or bins[i] == tmp:
            bins[i] = tmp
        else:
            print(-1)
            return

    if check(bins):
        print(sum(bins) + 1)
        ans = []
        for i, b in enumerate(bins):
            if b == 1:
                ans.append(str(i))
        print(' '.join(ans))

    else:
        print(-1)

if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    n=int(input())
    a=[0]+list(map(int,input().split()))
elif icase==3:
    f=open(r"C:\Users\nishi\999atcoder\ABCD040-151\ABC134D\testcase_12.in")
    ll=f.readline()
    n=int(ll)
    ll=f.readline()
    a=[0]+list(map(int,ll.split()))
    f.close()
b=[0]*(n+1)
for i in range(n//2+1,n+1):
    b[i]=a[i]
#    print(i,a[i])
    
for i in range(n//2,0,-1):
    i2=i*2
    asum=0
    while i2<=n:
        asum+=b[i2]
        i2+=i
    b[i]=(asum+a[i])%2
#    print(i,b[i],a[i],asum)
    
print(sum(b))
for i in range(1,len(b)):
    if b[i]==1:
        print(i,end=" ")
print(" ")

Submission status: Accepted

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

# 箱に書かれた数字が大きい順にボールを入れるか決定していくとi以上のiの倍数
# についてはすでにボールを入れるか入れないかを決定している

ans = [0] * N
for i in range(N - 1, -1, -1):
    if (i == N - 1):
        if (a[i] == 0):
            continue
        else:
            ans[i] = 1
            continue

    elif (i == 0):
        sum_a = sum(ans)
    else:
        sum_a = sum(ans[i::(i + 1)])

    if (a[i] == 0 and sum_a % 2 == 0):
        continue
    elif(a[i] == 0 and sum_a % 2 == 1):
        ans[i] = 1
    elif (a[i] == 1 and sum_a % 2 == 0):
        ans[i] = 1
    elif (a[i] == 1 and sum_a % 2 == 1):
        continue
    else:
        print(-1)
        exit()

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

if (M == 0):
    print(M)
    exit()
print(M)
print(*new_ans)

Submission status: Accepted

Solution code:
#入力
n=int(input())
a=list(map(int,input().split()))
#dpテーブル dp[i-1]はi番目の箱に入っているボールの数
dp=[0 for i in range(n)]
#初期条件
dp[n-1]=a[n-1]

for i in range(n,0,-1):
  num=0
  for j in range(i*2,n+1,i):
    num=num+dp[j-1]
  if num%2==a[i-1]:
    dp[i-1]=0
  else:
    dp[i-1]=1

print(dp.count(1))
for i in range(n):
  if dp[i]==1:
    print(i+1,end=" ")

Submission status: Accepted

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

dp = [-1]+[0]*n

for i in range(n,0,-1):
    j = 1
    isum = 0
    while j*i <= n:
        isum += dp[j*i]
        j += 1
    if isum%2 != l[i]%2:
        dp[i] =  1

ans = [i for i in range(1,n+1) if dp[i]==1]
print(len(ans))
if len(ans) != 0:
    print(*ans)

Submission status: Accepted

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n=II()
	A=[0]+LI()
	B=[0]*(n+1)

	for i in range(n,0,-1):
		a=A[i]
		if n//i>=2:
			for j in range(2,n//i+1):
				#print(i,j)
				a^=B[i*j]
		B[i]=a

	ans=[]
	for i,v in enumerate(B):
		if v:
			ans.append(i)

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













if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = []
c = []
for i in range(N):
    if i<N//2:
        b.append(-1)
    else:
        b.append(a[i])

for i in reversed(range(N//2)):
    t = 1
    s = 0
    while (i+1)*(t+1)<=N:
        s+=b[(i+1)*(t+1)-1]
        t+=1
    if s%2 != a[i]:
        b[i]=1
    else:
        b[i]= 0
#print(b)

bo = False
for j in range(N):
    if b[j]==1:
        bo = True
        c.append(str(j+1))
if bo:
    print(len(c))
    print(" ".join(c))
else:
    print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
m = 0
b = []
cnt = [[] for _ in range(n+1)]
for i in range(1, n+1):
    j = i
    c = 1
    while j*c <= n:
        cnt[j*c].append(i)
        c += 1

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

print(m)
print(*b[::-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
m = 0
b = []
cnt = [[] for _ in range(n+1)]
for i in range(1, n+1):
    j = i
    c = 1
    while j*c <= n:
        cnt[j*c].append(i)
        c += 1

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

if m == 0:
    print(m)
else:
    print(m)
    print(*b[::-1])

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

A = [0] + A
B = [0] * (N + 1)
sum_B = 0
for i in range(N, 0, -1):
    if sum(B[j] for j in range(i, N + 1, i)) % 2 != A[i]:
        B[i] = 1
        sum_B += 1
print(sum_B)
print(*[i for i, b in enumerate(B) if b])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
tmp = [0] * N
ans = []
ans_m = 0
for i in range(N, 0, -1):
    x = 0
    for j in range(i, N+1, i):
        x += tmp[j-1]
    if x % 2 != A[i-1]:
        tmp[i-1] = 1
        ans_m += 1
        ans.append(str(i))
print(ans_m)
if ans:
    print(" ".join(ans))

Submission status: Accepted

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

ans = [0]*n
for i in reversed(range(n)):
    j = i+1
    b = 0
    while j <= n:
        b += ans[j-1]
        j += (i+1)
    if b%2 == A[i]:
        ans[i] = 0
    else:
        ans[i] = 1
print(sum(ans))
B = []
for i in range(len(ans)):
    if ans[i] != 0:
        B.append(i+1)
print(*B)

Submission status: Accepted

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


ball = [0] * (n + 1)
ans = []

for i in range(n, 0, -1):
    s = 0
    j = i * 2
    while j <= n:
        s += ball[j]
        j += i

    if s % 2 != a[i]:
        ball[i] += 1
        ans.append(i)

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

Submission status: Accepted

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


for i in range(n,0,-1):
    if cnts[i]%2 != al[i-1]:
        boxs.append(i)
        for j in range(1, int(i**0.5)+1):
            if i%j == 0:
                cnts[j] += 1
                if j*j != i: cnts[i//j] += 1


print(len(boxs))
for b in boxs: print(b)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
B = [0 for _ in range(N+1)]
for i in range(N//2+1,N+1):
    B[i] = A[i]
for i in range(N//2,0,-1):
    cnt = A[i]
    for j in range(2,N//i+1):
        cnt = (cnt+B[i*j])%2
    B[i] = cnt
C = []
for i in range(1,N+1):
    if B[i]==1:
        C.append(i)
print(len(C))
print(*C)

Submission status: Accepted

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    A = [-1] + A
    B = [0] * (N + 1)
    for i in range(N, 0, -1):
        xor = 0
        for j in range(i * 2, N + 1, i):
            xor ^= B[j]
        B[i] = xor ^ A[i]
    print(sum(B))
    print(*[i for i, b in enumerate(B) if b == 1])

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)

Submission status: Accepted

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

B = [0] * (n + 1)  # 1-indexed
ans = []

for i in range(1, n + 1)[::-1]:
    _tmp = sum(B[i * 2::i])
    if _tmp % 2 != A[i]:
        B[i] += 1
        ans.append(str(i))

print(len(ans))
print(" ".join(ans))

Submission status: Accepted

Solution code:
N = int(input())
a = [0] + list(map(int,input().split()))
ans = [0]*(N+1)
for k in range(N,0,-1):
    temp = 0
    l = k
    while l <= N:
        temp += ans[l]
        l += k
    if a[k] == 1 and temp%2 == 0:
        ans[k] = 1
    elif a[k] == 0 and temp%2 == 1:
        ans[k] = 1
b = []
for k in range(1,N+1):
    if ans[k] == 1:
        b.append(k)
print(len(b))
print(*b)

Submission status: Accepted

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

ans = [0] * N
for i,a in enumerate(A[::-1]):
    n = m = N-i
    s = 0
    while m <= N:
        s += ans[m-1]
        m += n
    ans[n-1] = (s%2)^a

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
lis = [0]*(N+1)
for i in range(N,0,-1):
  k = i*2
  cnt = 0
  while k<=N:
    cnt ^= lis[k]
    k += i
  lis[i] = cnt^A[i-1]
print(lis.count(1))
ans = []
for i in range(1,N+1):
  if lis[i]==1:
    ans.append(i)
if len(ans):
  print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
ans = [0]*N
for i in range(N):
    target = N-1-i
    tmp = 0
    for k in range(target,N,target+1):
        tmp += ans[k]
    if tmp % 2 == arr[target]:
        ans[target] = 0
    else:
        ans[target] = 1
ans2 = []
for i in range(N):
    if ans[i] == 1:
        ans2.append(i+1)
print(len(ans2))
print(*ans2)

Submission status: Accepted

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

B=[0 for i in range(n)]
B[n//2:]=A[n//2:]

for i in range(n//2,0,-1):
    B[i-1]= (sum(B[i*2-1::i])%2 != A[i-1])

print(sum(B))
for i,j in enumerate(B):
    if j==1:
        print(i+1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[3]:


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


# In[6]:


mylist = [0]*(N+1)
i = N
while i > 0:
    idx = i
    x = 0
    while idx <= N:
        x += mylist[idx]
        idx += i
    if x%2 != a[i-1]:
        mylist[i] = 1
    i -= 1
ans = []
for i in range(1,N+1):
    if mylist[i] == 1:
        ans.append(i)
print(len(ans))
if ans:
    print(*ans)


# In[ ]:

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
*a, = map(int, input().split())
b = [0]*(n//2) + a[n//2:]
for i in reversed(range(n//2)):
    b[i] = sum(b[(i+1)*(j+1)-1] for j in range(n//(i+1)))&1 ^ a[i]
print(sum(b))
print(*[i+1 for i in range(n) if b[i]==1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
*a, = map(int, input().split())
b = [0]*(n//2) + a[n//2:]
for i in reversed(range(n//2)):
    b[i] = sum(b[(i+1)*(j+1)-1] for j in range(n//(i+1)))%2 ^ a[i]
print(sum(b))
print(*[i+1 for i in range(n) if b[i]==1])

Submission status: Accepted

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

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

num = sum(b)
if num == 0:
    print(0)
else:
    print(num)
    for i in range(n):
        if b[i] != 0:
            print(i+1)

Submission status: Accepted

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

# N = 10**5
# A = [random.randint(0,1) for _ in range(N)]
# print('A:',A)

ans_ = [0]*(N+1)

for n1 in range(N,0,-1):
    a = A[n1-1]
    sum_ = 0
    for n2 in range(2*n1,N+1,n1):
        sum_ += ans_[n2]
    if sum_%2 == a:
        ans_[n1] = 0
        
    elif sum_%2 != a:
        ans_[n1] = 1
        
# print('ans_:',ans_)

ans_list = []  
for s_ in range(len(ans_)):
    s=ans_[s_]
    if s == 1:
        ans_list.append(s_)
        
print(len(ans_list))
if len(ans_list)>0:
    print(' '.join(map(str,ans_list)))

Submission status: Accepted

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

for k in range(N,0,-1):
    p=A[k]
    for i in range(2*k,N+1,k):
        p^=B[i]
    B[k]=p

C=[k for k in range(1,N+1) if B[k]]
print(len(C))
if C:
    print(" ".join(map(str,C)))

Submission status: Accepted

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

for i,x in enumerate(reversed(A)):
	if not x == sum(b[N-i-1::N-i])%2:
		b[N-1-i] = 1

for i,x in enumerate(b):
	if x:
		r.append(i+1)

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

Submission status: Accepted

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

B = [0] * N
M = 0
ans = []
for i in range(N,0,-1):
    S, idx = 0, i-1
    while idx <= N-1:
        S += B[idx]
        idx += i

    if S % 2 != A[i-1]:
        B[i-1] = 1
        M += 1
        ans.append(i)
        

print(M)
for a in ans:
    print(a, end=" ")
print("")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    a = LI()

    half = N // 2
    ans = []
    ans.extend(a)
    for i in range(half - 1, -1, -1):
        sum_later = 0
        for j in range(2 * i + 1, N, i + 1):
            sum_later += ans[j]

        amari = sum_later % 2
        if amari == a[i]:
            ans[i] = 0
        else:
            ans[i] = 1
    print(sum(ans))
    for i in range(len(ans)):
        if ans[i] == 1:
            print(i + 1)


main()

Submission status: Accepted

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

Submission status: Accepted

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

c = [0] * (n+1)
d = []

for i in reversed(range(1, n+1)):
    s = sum(c[::i])
    if s % 2 != a[i]:
        c[i] += 1
        d.append(str(i))

print(sum(c))
if sum(c) > 0:
    print(" ".join(d))

Submission status: Accepted

Solution code:
def main():
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N = int(input())
    A = list(map(int,input().split()))

    #大きいほうから数える
    #調和級数なので計算量はOlogN
    ans = [0]*N
    for i in range(N,0,-1):
        tmp = 0
        if N//i == 1:
            ans[i-1] = A[i-1]
        else:
            max_n = N//i
            for j in range(1,max_n):
                tmp += ans[i*(j+1)-1]
            tmp%=2

            ans[i-1] = tmp^A[i-1]

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

    print(ans_n)
    print(*ans_li)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
d = [0]*N
for i in reversed(range(1,N+1)):
    n=1
    t=0
    while i*n<=N:
        t+=d[i*n-1]
        n+=1
    d[i-1]=(t+A[i-1])%2
res = [i+1 for i,x in enumerate(d) if x]
print(len(res))
print(*res)

Submission status: Accepted

Solution code:
def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table


N = int(input())
A = list(map(int, input().split()))
temp = [0] * N
for n in reversed(range(1,N+1)):
    if (A[n-1] + temp[n - 1])%2 == 0:
        temp[n - 1] = 0
        continue
    for a in divisors(n):
        temp[a-1] += 1


res = list(i+1 for i, _ in enumerate(temp) if temp[i])
print(len(res))
print(*res)

"""
4
1 1 1 1
"""

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit
from collections import defaultdict as dd
n = int(input())
A = list(map(int, input().split()))

dic = dd(int)
for i, a in enumerate(A):
    dic[i+1] = a

baisu = dd(set)
for num in range(1, n+1):
    for i in range(1, n+1):
        if num * i > n:
            break
        baisu[num * i].add(num)
#print(baisu)

box = dd(int)

#dic -> baisu -> box
for num in range(n, 0, -1):
    kosu = dic[num]
    for yakusu in list(baisu[num]):
        dic[yakusu] += kosu
        dic[yakusu] %= 2
        box[num] += kosu

ans = []
for i in range(1, n+1):
    if box[i] >= 1:
        ans.append(i)
print(sum([i > 0 for i in ans]))
print(*ans, sep=" ")

Submission status: Accepted

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

memo = [0]*(N+1)

for i in range(N,0,-1):
  j = 2
  cnt = 0
  while i*j <= N:
    cnt ^= memo[i*j]
    j += 1
  memo[i] = cnt^As[i]
  
print(sum(memo))
rlt = []
for i in range(1,N+1):
  if memo[i] == 1:
    rlt.append(i)
    
print(' '.join(map(str, rlt)))

Submission status: Accepted

Solution code:
n = int(input())
A = [None] + [int(i) for i in input().split()]  # 1-based index
ans = []
choose = [0] * (n + 1)


for i in range(n, 0, -1): # 大きい数から評価する
    x = sum(choose[2 * i::i]) # その箱の倍数に入っている玉の和を求める
    if x % 2 == A[i]: # 偶奇の一致を確認
        continue
    choose[i] += 1
    ans.append(str(i))

print(len(ans))
print(" ".join(ans))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

ans = [-1]*N
for i in range(N-1, -1, -1):
    a = As[i]
    idx = i+1
    if idx*2>N:
        ans[i] = a
        continue
    cnt = 2
    per = 0
    while cnt*idx<=N:
        per += ans[cnt*idx-1]
        cnt += 1
    per %= 2
    ans[i] = 1 if per!=a else 0
print(sum(ans))
if sum(ans):
    print(*[i+1 for i, x in enumerate(ans) if x!=0])

Submission status: Accepted

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

box = [-1] * (N + 1)
ball_in_list = []
# 箱について(i = N, N-1, ..., 1)
for i in range(N, 0, -1):
    cnt = 0
    # (N//i)*i, ..., 3*i, 2*i
    for j in range((N // i) * i, 2 * i - 1, -i):
        cnt += box[j]

    # 偶奇が同じならボールは入れない
    if cnt % 2 == a[i - 1]:
        box[i] = 0
    # 偶奇が異なる時、ボールを入れる、その行為を記録
    else:
        box[i] = 1
        ball_in_list.append(i)

print(len(ball_in_list))
print(*ball_in_list)

Submission status: Accepted

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

B = [0]*n

for i in range(n)[::-1]:
  tmp = 0
  j = i+1
  
  while j<=n:    
    tmp += B[j-1]
    j += i+1
    
  if tmp%2 != A[i]:    
    B[i] = 1

print(sum(B))
print(*[i+1 for i in range(n) if B[i]])

Submission status: Accepted

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

ans = [0]*n

for i in range(n)[::-1]:
  if i >= n//2:
    ans[i] = A[i]
  else:
    tmp = 0
    j = i+1
    while j<=n:
      tmp += ans[j-1]
      j += i+1
    if A[i] == 1:
      if tmp % 2 != A[i]:
        ans[i] = A[i]              
    else:      
      if tmp % 2 == 1:
        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 = tuple(map(int, input().split()))

state = [0] * (N + 1)
for i in range(N, 0, -1):
    if N < i + i:
        state[i] = A[i-1]
    else:
        state[i] = A[i-1]
        j = i + i
        while j <= N:
            state[i] ^= state[j]
            j += i
ans = [str(i) for i, x in enumerate(state) if x == 1]
print(len(ans))
if ans:
    print(" ".join(ans))

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int,input().split()))
di = [100]*(n+1)
di[0] = 0
for i in range(n):
    N = n - i
    num = int(n/N)
    fi = []
    for j in range(num):
        fi.append(N*(j+1))
    p = 0
    for k in fi:
        p += di[k]
    if (p - 100)%2 == ls[fi[0]-1]:
        di[fi[0]] = 0
    else:
        di[fi[0]] = 1
print(sum(di))
for e in range(1,len(di)):
    if di[e] == 1:
        print(e,end=" ")

Submission status: Accepted

Solution code:
n = int(input())
a = [0] + list(map(int, input().split()))
ans = []
for i in range(n, 0, -1):
    j = 2 * i
    while j <= n:
        a[i] ^= a[j]
        j += i
    if a[i] == 1:
        ans.append(i)
print(len(ans))
if ans:
    print(' '.join(list(map(str, ans))))

Submission status: Accepted

Solution code:
n = int(input())
a = [0] + list(map(int, input().split()))
x = a[:]
ans = []
for i in range(n, 0, -1):
    j = 2 * i
    while j <= n:
        x[i] ^= x[j]
        j += i
    if x[i] == 1:
        ans.append(i)

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

Submission status: Accepted

Solution code:
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    p2 = [0]*(n+1)
    for i in range(n,0,-1):
        sm = 0
        for j in range(i,n+1,i):
            sm += p2[j]
        p2[i] = (a[i-1]-sm)%2

    sm = sum(p2)
    print(sm)
    ans = []
    for i,pi in enumerate(p2):
        if pi:
            ans.append(str(i))

    print(" ".join(ans))
    return None

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

y = [0] * (N + 1)
for i in reversed(range(1, N + 1)):
    cnt = 0
    for j in range(2 * i, N + 1, i):
        cnt += y[j]
    if cnt % 2 != X[i - 1]:
        y[i] = 1

print(sum(y))
if sum(y):
    print(*[i for i in range(N + 1) if y[i]])

Submission status: Accepted

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

ans_ls = [0]*N
for i in range(N):
    temp = 0
    num = N - i
    j = 1
    while num*j <= N:
        temp += ans_ls[num*j-1]
        j += 1
    if (temp + a[num-1])%2 == 1:
        ans_ls[num-1] = 1
        m_list.append(str(num))
        m_num += 1
m_list.sort()

print(m_num)
print(' '.join(m_list))

Submission status: Accepted

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

for i in range(n, 0, -1):
    k, cnt = 0, 0
    while True:
        if k+i > n:
            break
        if list_N[k+i-1] == 1:
            cnt += 1
        k += i
    list_N[i-1] = (list_A[i-1]+cnt) % 2

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0] + list(map(int, input().split()))
b = [0]*(n+1)
b[-1] = a[-1]
ans = []
for i in range(n, 0, -1):
    cnt = 0
    bi = i
    i += bi
    while i <= n:
        cnt += b[i]
        i += bi

    if (cnt%2) == a[bi]:
        b[bi] = 0
    else:
        b[bi] = 1
        ans.append(bi)

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

Submission status: Accepted

Solution code:
N = int(input())
a = tuple(map(int, input().split()))
b = [-1] * N
for i in range(N//2, N):
    b[i] = 1 if a[i] == 1 else 0
for j in range(N//2-1, -1, -1):
    acc = sum([b[i] for i in range(2*j+1, N, j+1)])%2
    b[j] = acc ^ a[j]
ans = len([i for i in b if i == 1])
print(ans)
if ans == 0:
    exit()
print(*[j+1 for j, v in enumerate(b) if v == 1])

Submission status: Accepted

Solution code:
N = int(input())
a = tuple(map(int, input().split()))
b = [-1] * N
for i in range(N//2, N):
    b[i] = 1 if a[i] == 1 else 0
for j in range(N//2-1, -1, -1):
    acc = sum([b[i] for i in range(2*j+1, N, j+1)])
    if a[j] == 1 and acc % 2 == 0:
        b[j] = 1
    elif a[j] == 0 and acc % 2 != 0:
        b[j] = 1
    elif a[j] == 0 and acc % 2 == 0:
        b[j] = 0
    elif a[j] == 1 and acc % 2 != 0:
        b[j] = 0
if -1 in b:
    print(-1)
    exit()
ans = len([i for i in b if i == 1])
print(ans)
if ans == 0:
    exit()
print(*[j+1 for j, v in enumerate(b) if v == 1])

Submission status: Accepted

Solution code:
N = int(input())
Ali = list(map(int,input().split()))
bli = [0]*(N+1)
M = 0

for z in range(N):
  i = N-z
  #iの倍数の箱の和%2がAliと同じか調べる
  sb = 0
  for j in range(i*2,N+1,i):
    sb += bli[j]
  if sb%2 != Ali[i-1]:
    bli[i] = 1
    M += 1
    
print(M)

cnt = 0
for i in range(N+1):
  if bli[i] == 1:
    cnt += 1
    if cnt == M:
      print(i)
    else:
      print(i,end=" ")

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:
def main():
    import sys

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

    n = int(input())
    a = [0] + list(map(int, input().split()))
    for i in range(n, 0, -1):
        k = 1
        flag = 0
        while i*k <= n:
            flag ^= a[i*k]
            k += 1
        if flag != a[i]:
            a[i] ^= 1
    ans = [i for i in range(n+1) if a[i] == 1]
    if ans == []:
        print(0)
    else:
        print(len(ans))
        print(*ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
lst=list(map(int,input().split()))
anslst=[None]*n
for i in range(n,0,-1):
    amari=lst[i-1]
    tmp=i*2
    kosuu=0
    while tmp-1<n:
        if anslst[tmp-1]==1:
            kosuu+=1
        tmp+=i
    kosuu%=2
    if kosuu==amari:
        anslst[i-1]=0
    else:
        anslst[i-1]=1
cnt=0
ans=[]
for i in range(n):
    if anslst[i]==1:
        cnt+=1
        ans.append(i+1)
print(cnt)
print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]+list(map(int,input().split()))
d=[[] for _ in range(n+1)]
p=[0]*(n+1)
for i in range(1,n+1):
  for j in range(i,n+1,i):
    d[j]+=[i]
ans=[]
for i in range(n,0,-1):
  if a[i]!=p[i]:
    ans+=[i]
    for j in d[i]:
      p[j]=1-p[j]
  else:p[i]=0
print(len(ans))
print(*ans)