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: Time Limit Exceeded

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

M = 0
box_dict = {}
for i in reversed(range(N)):
    idx = i + 1
    multi_sum = 0
    for key, value in box_dict.items():
        if key % (idx * 2) == 0:
            multi_sum += value
    if a_list[i] - multi_sum == 0:
        box_dict[idx] = 0
    else:
        box_dict[idx] = 1
        M += 1

print(M)
if M > 0:
    b_list = [key for key, value in box_dict.items() if value == 1]
    print(" ".join(map(str, b_list)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
output = np.zeros(N)

output[N//2:]=A[N//2:]

t = N//2-1
for j in range(N//2):
    for i in range(N//(t+1)-1):
        output[t]= (output[t]+output[(t+1)*(i+2)-1])%2
    output[t]=int(output[t] != A[t])
    t -= 1

ans = ""
flag = 0
for j in range(N):
    if output[j]==1:
        ans += str(j+1) + " "
        flag += 1
print(flag)
if flag > 0:
    ans = ans[:-1]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_list = [int(x) for x in input().split()]
cnt = 0
b_list = []
for i in range(len(a_list), 0, -1):
    if ( a_list[i-1] != len(list(filter(lambda b: b%i == 0, b_list))) %2):
        b_list.append(i)
M = len(b_list)
print(M)
if (M>0):
    print(" ".join([str(b) for b in b_list]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())  
a = np.array(input().split(), dtype=np.int64)
b = np.zeros(N)
M = np.arange(N) + 1
    
for i in np.arange(N)[::-1]:
    A = a[np.where(M % (i+1) == 0)]
    if a[i] == 0:
        if np.sum(A) % 2  == 0:
            b[i] = a[i]
        else:
            b[i] = (a[i] + 1) % 2
    else:
        if np.sum(A) % 2  == 1:
            b[i] = a[i]
        else:
            b[i] = (a[i] + 1) % 2    
        
ans = np.where(b == 1)[0] + 1

print(np.size(ans))

if np.size(ans) > 0:
    print(*ans.astype(np.int32))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
ans = []
for i in range(N-1, 0, -1):
    Sum = 0
    for k in ans:
        if k % (i+1) == 0:
            Sum += 1
    if Sum%2 != A[i]:
        ans.append(i+1)

if len(ans)%2 != A[0]:
    ans.append(1)
print(len(ans))
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = 1 == int(A[i])
    return A

if __name__ == '__main__':
    N = int(input())
    a = InputToInt()

    b = []
    M = 0
    for i in range(N):
        if a[N-1-i]:
            b.append(N-i)
            M += 1
            for j in range(N-1-i):
                if (N-i)%(j+1) == 0:
                    a[j] = not a[j]
    print(M)
    for i in b:
        print(i, end=' ')

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc134/tasks/abc134_d
n = int(int(input()))
a = [int(i) for i in input().split()]

b = [0] * n
for i in reversed(range(1, n + 1)):
    cnt = 0
    c = []
    for j in range(1, n + 1):
        if j % i == 0 and j != i:
            cnt += 1
            c.append(j)
    s = 0
    for j in c:
        s += a[j - 1]
    #print(i, cnt, c, s)
    if s % 2 == a[i - 1]:
        b[i - 1] = 0
    else:
        b[i - 1] = 1
#print(b)
e = sum(b)
print(e)

if e != 0:
    d = []
    for i in range(n):
        if b[i] == 1:
            d.append(i + 1)
    print(' '.join(map(str, d)))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = list(map(int,input().split()))
    r = []
    for i in range(n,0,-1):
        c = sum(x % i == 0 for x in r)
        c1 = c % 2
        if c1 != s[i-1]:
            r.append(int(i))

    print(len(r))
    if len(r) > 0:
        for i in range(len(r)):
            r[i] = str(r[i])
        print(" ".join(r))
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

N_ = N
half_N = (N // 2)
ans = []
while N_ > 0:
	if N_ > half_N:
		if a[N_ - 1] == 1:
			ans.append(N_)
	else:
		count_ = 0
		for i in ans:
			if i % N_ == 0:
				count_ += 1
		if count_ % 2 != a[N_ - 1]:
			ans.append(N_)
	N_ -= 1

print(len(ans))
for i in ans:
	print(i,end = " ")

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(4100000)

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    N = [int(x) for x in sys.stdin.readline().split()][0]
    a_list = [int(x) for x in sys.stdin.readline().split()]

    logger.debug('{} {}'.format(N, a_list))

    box_list = [0 for _ in range(N)]

    for i in reversed(range(N)):
        suma = 0
        for j in range(i + 1, N):
            if ((j + 1) % (i + 1) == 0):
                suma += box_list[j]

        r = suma % 2
        if r != a_list[i]:
            box_list[i] = 1

    s = sum(box_list)
    print(s)

    if s > 0:
        print(' '.join(
            [str(i + 1) for i in range(len(box_list)) if box_list[i]]))


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1 0 0"""
        output = """1
1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5
0 0 0 0 0"""
        output = """0"""
        self.assertIO(input, output)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N=int(input())
A=deque(list(map(int,input().split())))
D={}
ans=""
M=0
for i in range(N):
    a=A.pop()
    if N//(N-i)==1:
        D[N-i]=a
        if a==1:
            M+=1
            ans=ans+str(N-i)+" "
    else:
        p=N//(N-i)
        memo=0
        for j in range(1,p):
            memo+=D[(N-i)*(j+1)]
        if memo%2==a:
            D[N-i]=0
        else:
            D[N-i]=1
            M+=1
            ans=ans+str(N-i)+" "
ans=ans[:-1]
print(M)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


N = int(input())
inputs = np.array(input().split(), dtype=np.uint8)
inputs = inputs[::-1]
boxes = np.zeros_like(inputs)
M = 0
outputs = []

for i, a in enumerate(inputs):
    num = N - i
    idxs = np.arange(num,  N+1, num) - 1
    S = boxes[idxs].sum()
    if S % 2 != a:
        M += 1
        boxes[num-1] = 1
    # print(num, idxs+1, S, boxes)

print(M)
if M != 0:
    outputs = np.where(boxes == 1)[0] + 1
    outputs = [str(x) for x in outputs]
    print(' '.join(outputs))

Submission status: Time Limit Exceeded

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

memo = {}
memo_size = min(1000,N)
for i in range(1, memo_size+1):
    memo[i] = 0

boxin = []
for cnt in range(N, 0, -1):
    a = ax[cnt-1]
    if cnt < memo_size:
        memo_cnt = memo[cnt]
    else:
        i = 2
        memo_cnt = 0
        while 1:
            test_val = i * cnt
            if test_val > N:
                break
            if test_val in boxin:
                memo_cnt += 1
            i += 1
    if a != memo_cnt % 2:
        boxin.append(cnt)
        for i in range(1,memo_size+1):
            if cnt % i == 0:
                memo[i] += 1

box = len(boxin)
print(box)
if box != 0:
    boxin.reverse()
    print(' '.join(map(str, boxin)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ai = [int(x) for x in input().split()]
bn = [0] * n
cn = [0] * n
dn = [0] * n

for i in range(0,n):
    j = n - 1 - i
    if (n//(j+1)<1):
        bn[j] = ai[j]
    else:
        bn[j] = (cn[j] + ai[j]) % 2

    if bn[j] == 1:
        for k in range(0,((j+1)//2)+1):
            if (j+1)%(k+1) == 0:
                cn[k] += 1

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

Submission status: Time Limit Exceeded

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

memo = {}
memo_size = min(100,N)
for i in range(1, memo_size+1):
    memo[i] = 0

boxin = []
for cnt in range(N, 0, -1):
    a = ax[cnt-1]
    if cnt < memo_size:
        memo_cnt = memo[cnt]
    else:
        i = 2
        memo_cnt = 0
        while 1:
            test_val = i * cnt
            if test_val > N:
                break
            if test_val in boxin:
                memo_cnt += 1
            i += 1
    if a != memo_cnt % 2:
        boxin.append(cnt)
        for i in range(1,memo_size+1):
            if cnt % i == 0:
                memo[i] += 1

box = len(boxin)
print(box)
if box != 0:
    boxin.reverse()
    print(' '.join(map(str, boxin)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
As.insert(0, 0)
Ans = [0 for _ in range(N + 1)]
Ans[N] = As[N]
for i in range(N - 1, 0, -1):
    p = i * 2
    s = 0
    while p <= N:
        s ^= Ans[p]
        p += i
    Ans[i] = 0 if s == As[i] else 1
M = sum(Ans)
print(M)
if M > 0:
    bs = ""
    for i in range(1, N + 1):
        if Ans[i] != 0:
            bs += "%d " % i
    bs = bs.rstrip(" ")
    print(bs)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

A=[int(i) for i in input().split()]
memo=[0 for i in range(n)]
ans=[]

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

    # divisors.sort()
    return divisors


for i in range(n-1,-1,-1):
    if not memo[i]==A[i]:
        ans.append(str(i+1))
        make_divisors(i+1)

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

Submission status: Time Limit Exceeded

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

ans = set()
cnt = [0] * (n + 1)

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

        st = set()
        j = 1
        while j * j <= i:
            if i % j == 0:
                st.add(j)
                st.add(i // j)
            j += 1
        for d in st:
            cnt[d] += 1

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

Submission status: Time Limit Exceeded

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

# print(N, A)
B = [0]*N

for i in range((N + 1)//2, N + 1):
    B[i - 1] = A[i - 1]

for i in range(N // 2):
    index = N // 2 - i - 1
    num = 0
    for j in range(N):
        v = N - j - 1
        if (v + 1) % (index + 1) == 0:
            num += B[v]
    if num % 2 != A[index]:
        B[index] = 1
# print(B)

M = 0
for b in B:
    if b == 1:
        M += 1
print(M)
ANS = []
for i in range(N):
    if B[i] == 1:
        ANS.append(str(i + 1))
if M > 0:
    ans = ' '.join(ANS)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
b_list = []

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

for i in range(n):
    if a_list[-i-1] == 1:
        b_list.append(n-i)
        for j in make_divisors(n-i):
            a_list[j-1] = abs(a_list[j-1]-1)

b_list.reverse()
x = len(b_list)
print(x)
if x != 0:
    print(*b_list)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
D={}
ans=""
M=0
for i in range(N):
    if N//(N-i)==1:
        a=A[N-i-1]
        D[N-i]=a
        if a==1:
            M+=1
            ans=ans+str(N-i)+" "
    else:
        a=N//(N-i)
        memo=0
        for j in range(1,a):
            memo+=D[(N-i)*(j+1)]
        if memo%2==A[N-i-1]:
            D[N-i]=0
        else:
            D[N-i]=1
            M+=1
            ans=ans+str(N-i)+" "
ans=ans[:-1]
print(M)
print(ans)

Submission status: Time Limit Exceeded

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

MOD = 2  # type: int

def solve(N: int, A: "List[int]"):
    ans = []
    for i in range(N,0,-1):
        c = 0
        for j in range(2,N + 1):
            if i * j <= N:
                if A[i*j-1] == 1:
                    c += 1
        if A[i-1] == 0:
            if c % 2 == 1:
                ans.append(str(i))
        else:
            if c % 2 == 0:
                ans.append(str(i))

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


    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
AN = [int(i) for i in input().split()]
reversed = reversed(AN)
result = []

for i, A in enumerate(reversed):
    index=N-i
    if sum([1 for i in result if i % index == 0])%2==A:
        continue
    else:
        result.append(index)

print(len(result))
print(' '.join([str(i) for i in result]))

Submission status: Time Limit Exceeded

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

def factor(num):
    sqrt = num**0.5
    for i in range(1,int(num**0.5)+1):
        if i == sqrt:
            temp[i] += 1
        elif num%i == 0:
            temp[i] += 1
            temp[num//i] += 1
    return


for a,i in zip(A[::-1],range(N-1,-1,-1)):
    if a == 1 and temp[i+1] == 0:
        factor(i+1)
        Ans.append(i+1)
    elif temp[i+1]%2 != a:
        factor(i+1)
        Ans.append(i+1)
if len(Ans) == 0:
    print(0)
else:
    print(len(Ans))
    print(*Ans,sep = " ")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
cur = [0 for i in range(N)]
ball = []
ball_num = 0
for x in range(N):
	i = N-1 - x
	n = i + 1
	if A[i] != cur[i]:
		ball.append(n)
		ball_num += 1
		for j in range(n // 2 + 1):
			m = j + 1
			if m * m > n:
				break
			if n % m == 0:
				cur[j] = 1 - cur[j]
				if n//m != m:
					cur[n//m - 1] = 1 - cur[n//m - 1]  
print(ball_num)
print(" ".join(list(map(str, ball))))

Submission status: Time Limit Exceeded

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

ans = []
for n in range(N, 0, -1):
    a_i = a[n-1]
    cnt = 0
    n2 = n*2
    while n2 <= N:
        if n2 in ans:
            cnt += 1
        n2 += n
    if cnt % 2 != a_i:
        ans.append(n)

print(len(ans))
if len(ans) != 0:
    print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ai = [int(x) for x in input().split()]
bn = [0] * n
cn = [0] * n
dn = [0] * n

for i in range(0,n):
    j = n - 1 - i
    if (n//(j+1)<1):
        bn[j] = ai[j]
    else:
        bn[j] = (cn[j] + ai[j]) % 2

    if bn[j] == 1:
        for k in range(0,j):
            if (j+1)%(k+1) == 0:
                cn[k] += 1

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=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)
    return divisors

b=[0 for _ in range(n)]
for i in range(n):
    y=a[n-i-1]
    b[n-i-1]=y
    divs = make_divisors(n-i)
    for x in divs:
        a[x-1] = a[x-1] ^ y
print(sum(b))
l=[]
for i in range(n):
    if b[i] == 1:
        l.append(i+1)
print(' '.join(map(str,l)))

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [0] + list(map(int, input().split()))

    M = 0
    ans = ''
    B = [0] * (N+1)
    for i in range(N, 0, -1):
        cnt = 0
        for j in range(2*i, N+1, i):
            cnt += B[j]

        if A[i] != cnt % 2:
            B[i] += 1
            M += 1
            ans = str(i) + ' ' + ans

    if M == 0:
        print(0)
    else:
        print(M)
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

A=[int(i) for i in input().split()]
memo=[0 for i in range(n)]
ans=[]

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

niku=make_divisors(12)

for i in range(n-1,-1,-1):
    if not memo[i]==A[i]:
        ans.append(str(i+1))
        for p in make_divisors(i+1):
            memo[p-1]^=1

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

Submission status: Time Limit Exceeded

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

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

if a == b:
    print(sum(b))
    for i in range(N):
        if b[i] == 1:
            print(i+1 ,end=' ')
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

N = int(input())
A = [None] + [int(x) for x in input().split()]

answer = []
choose = np.zeros(N+1, dtype=np.int32)

for n in range(N,0,-1):
    x = choose[2*n::n].sum()
    if x % 2 == A[n]:
        continue
    choose[n] += 1
    answer.append(str(n))

print(len(answer))
print(' '.join(answer))

Submission status: Time Limit Exceeded

Solution code:
def yakusu(n):
    results = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            results.append(i)
            results.append(n // i)
    return results

N = int(input())
A = list(map(int, input().split()))
is_odd = [False for i in range(N+1)]
A.insert(0, 0)
ans = []
for i in range(N, 0, -1):
    if A[i] == 1:
        if not is_odd[i]:
            ans.append(i)
            for y in set(yakusu(i)):
                is_odd[y] = not is_odd[y]
    elif A[i] == 0:
        if is_odd[i]:
            ans.append(i)
            for y in set(yakusu(i)):
                is_odd[y] = not is_odd[y]
print(len(ans))
if len(ans) != 0:
    print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

A=[int(i) for i in input().split()]
memo=[0 for i in range(n)]
ans=[]

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

niku=make_divisors(12)

for i in range(n-1,-1,-1):
    if not memo[i]%2==A[i]:
        ans.append(str(i+1))
        for p in make_divisors(i+1):
            memo[p-1]+=1

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
As.insert(0, 0)
Ans = [0 for _ in range(N + 1)]
Ans[N] = As[N]
for i in range(N - 1, 0, -1):
    k = 2
    s = 0
    while True:
        p = k * i
        if p > N:
            break
        s += Ans[p]
        k += 1
    Ans[i] = 0 if s % 2 == As[i] else 1
M = sum(Ans)
print(M)
if M > 0:
    bs = ""
    for i in range(1, N + 1):
        if Ans[i] != 0:
            bs += "%d " % i
    bs = bs.rstrip(" ")
    print(bs)

Submission status: Time Limit Exceeded

Solution code:
def divisors(n):
    ds = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ds.append(i)
            if i != n // i:# and i != 1:
                ds.append(n//i)
    # divisors.sort()
    return ds

n = int(input())
aa = list(map(int, input().split()))
counts = {}
balls = {}


for i in range(len(aa)):
    if aa[i] == 1:
        counts[i + 1] = 1
    else:
        counts[i + 1] = 0

for i in range(n, 0, -1):
    #print(f'i = {i}, counts={counts}')
    if counts[i] % 2 == 0:
        continue
    # put ball in i
    balls[i] = True
    ds = divisors(i)
    for d in ds:
        counts[d] += 1
balls = list(balls.keys())
print(len(balls))
if len(balls) > 0:
    print(' '.join(map(str, balls)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = 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)
    return divisors

b = []
start = n // 2 + 1
end = n
num = [0] * n
while True:
    if start > end:
        break
    else:
        for i in range(end, start - 1, -1):
            if a[i - 1] != num[i - 1]:
                b.append(i)
                divisors = make_divisors(i)
                for j in divisors:
                    a[j - 1] += 1
                    a[j - 1] %= 2
        end = start - 1
        start = end // 2 + 1
b.sort()
print(len(b))
if len(b) >= 2:
    print(" ".join(map(str, b)))
elif len(b) == 1:
    print(b[0])
else:
    pass

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def divisors(m: int):
    i = 1
    div = []
    while i * i <= m:
        if m % i == 0:
            div.append(i)
            div.append(m // i)
        i += 1

    return list(set(div))

n = ni()
a = [0] + list(li())
b = [0]*(n+1)
ans = []
for i in range(n, 0, -1):
    into = False
    if b[i] % 2 != a[i]:
        b[i] += 1
        ans.append(i)
        into = True

    if into:
        bi_div = divisors(i)

        for divi in bi_div:
            b[divi] += 1

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

Submission status: Time Limit Exceeded

Solution code:
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

n = int(input())
a = list(map(int, input().split()))
b = []
lst = [0] * n
for i, x in reversed(list(enumerate(a))):
  if lst[i] % 2 != x:
    for y in make_divisors(i+1):
      lst[y-1] += 1
    b.append(i+1)
print(len(b))
if len(b) > 0:
  print(*reversed(b))

Submission status: Time Limit Exceeded

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

Submission status: Accepted

Solution code:
#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#mod = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    A=LIST()
    flg=True
    la=len(A)
    bool=[False]*(n+1)
    B=[]
    for i in range(la-1,-1,-1):
        a=A[i]
        s=i+1
        temp=0
        for j in range(n//s+1):
            if j==0:
                continue
            if bool[j*s]:
                temp+=1
        
        if temp%2!=a:
            B.append(s)
            bool[s]=True
    
    B=sorted(B)
    print(len(B))
    if len(B)!=0:
        print(*B)

            

if __name__=='__main__':
    do()

Submission status: Accepted

Solution code:
import sys


def IN_I(): return int(sys.stdin.readline().rstrip())
def IN_LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IN_S(): return sys.stdin.readline().rstrip()
def IN_LS(): return list(sys.stdin.readline().rstrip().split())


N = IN_I()
a = [0] + IN_LI()
b = [0] * (N + 1)
ans = []

for i in range(N, 0, -1):
    tmp = 0
    for j in range(2 * i, N + 1, i):
        tmp += b[j]
    if tmp % 2 != a[i]:
        b[i] = 1
        ans.append(i)
if len(ans) == 0:
    print(0)
else:
    print(len(ans))
    print(' '.join(map(str, ans)))

Submission status: Accepted

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

for i in reversed(range(1, N + 1)):
    p = (N // i) * i
    s = 0
    while res[p - 1] != -1:
        s += res[p - 1]
        s %= 2
        p -= i
    res[p - 1] = (A[p - 1] - s) % 2

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n = int(input())
a = [0, *(int(x) for x in input().split())]
divisors = [[] for i in range(n + 1)]
for i in range(1, n + 1):
    for j in range(i, n + 1, i):
        divisors[j].append(i)
ans = []
for i in reversed(range(1, n + 1)):
    if a[i]:
        for j in divisors[i]:
            a[j] ^= 1
        ans.append(i)
print(len(ans))
print(*ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    
    n = I()
    a = [0] + LI()
    ans = [0 for _ in range(n+1)]

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

    print(len(ans_lst))
    print(*ans_lst)

    
main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = [0] * N
ans = 0 
from collections import deque        
ansL = deque()
for i in range(N):
    m = N - i 
    count = 0
    for k in range(1,N//m+1):
        count += b[m*k-1]
    if count % 2 != a[m-1]:
        b[m-1] = 1
        ans += 1
        ansL.appendleft(m)    
print(ans)
print(*ansL)

Submission status: Accepted

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

for i in reversed(range(1, N+1)):
    tmp = 0
    for j in range(i, N+1, i):
        tmp += b[j]
            
    if(tmp%2 == a[i]):
        b[i] = 0
    else:
        b[i] = 1


ans = []
for i, j in enumerate(b):
    if(j == 1):
        ans.append(i)
print(len(ans))
if(len(ans)):
    print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]+list(map(int,input().split()))
b=[0]*(n+1)
for i in reversed(range(1,n+1)):
    ans=0
    for j in range(i,n+1,i):
        ans+=b[j]
    if ans%2==a[i]:
        b[i]=0
    else:
        b[i]=1
c_=[]
for c,d in enumerate(b):
    if d==1:
        c_.append(str(c))
print(len(c_))
print(' '.join(c_))

Submission status: Accepted

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

Submission status: Accepted

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

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