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:
import sys
from math import sqrt
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
def divisor_set(N: int) -> set:
    s = {1, N}
    for i in range(2, int(sqrt(N))+1):
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s
 
N=INT()
A=LIST()
 
A2=[0]*N
B=[]
for i in range(N-1, -1, -1):
    if A[i]!=A2[i]:
        B.append(i+1)
        div=divisor_set(i+1)
        for num in div:
            A2[num-1]=1-A2[num-1]
        
print(len(B))
print(*B)

Submission status: Time Limit Exceeded

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

for i in reversed(range(N)):
    if A[i]:
        put.append(i+1)
        # iを素因数分解して、約数に1をxorしていく
        tmp = 1
        n = i+1
        while tmp*tmp <= n:
            if n % tmp == 0:
                A[tmp-1] ^= 1
                if tmp != n//tmp:
                    A[n//tmp-1] ^= 1
            tmp += 1


if len(put) > 0:
    print(len(put))
    print(*put)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = [0]*N
put = []

for i in reversed(range(N)):
    if A[i] != B[i]:
        put.append(i+1)
        # iを素因数分解して、約数に1をxorしていく
        tmp = 1
        n = i+1
        while tmp*tmp <= n:
            if n % tmp == 0:
                B[tmp-1] ^= 1
                if tmp != n//tmp:
                    B[n//tmp-1] ^= 1
            tmp += 1


if len(put) > 0:
    print(len(put))
    print(*put)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for k in reversed(range(1, N + 1)):
    if k == 1:
        if len(ans) % 2 != a[k - 1]:
            ans.append(k)
        continue
    t = N // k
    cnt = 0
    for i in range(1, t + 1):
        if i * k in ans:
            cnt += 1
    if cnt % 2 != a[k - 1]:
        ans.append(k)

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for k in reversed(range(1, N + 1)):
    t = N // k
    cnt = 0
    for i in range(1, t + 1):
        if i * k in ans:
            cnt += 1
    if cnt % 2 != a[k - 1]:
        ans.append(k)

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
from math import sqrt

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def divisor_set(N: int) -> set:
    """ 約数の列挙・個数 """
    # 1とその数はデフォで入れとく
    s = {1, N}
    # 終点はルート切り捨て
    for i in range(2, int(sqrt(N))+1):
        # 割り切れるなら、iとN/iを追加
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

N=INT()
A=LIST()

A2=[0]*N
B=[]
for i in range(N-1, -1, -1):
    if A[i]!=A2[i]:
        B.append(i+1)
        div=divisor_set(i+1)
        for num in div:
            A2[num-1]=1-A2[num-1]
        
print(len(B))
print(*B)

Submission status: Time Limit Exceeded

Solution code:

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

M = 0
ans_lst = [0] * N

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

m = sum(ans_lst)    


print(m)
ans_str = ""
for i in range(N):
    if ans_lst[i] == 1:
        ans_str += str(i+1) + " "
print(ans_str)

Submission status: Time Limit Exceeded

Solution code:

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

M = 0
ans_lst = [0] * N

t = 0
for i in range(N-1, -1, -1):
    t = sum(ans_lst[i::i+1])
        
    if t % 2 != a_lst[i]:
        ans_lst[i] = 1
    


m = 0
for i in range(N):
    m += ans_lst[i]
    


print(m)
ans_str = ""
for i in range(N):
    if ans_lst[i] == 1:
        ans_str += str(i+1) + " "
print(ans_str)

Submission status: Time Limit Exceeded

Solution code:
import sys,math
n = int(input())
a = list(map(int,input().split()))
select = [0 for _ in range(n+1)]
mark = [0 for _ in range(n+1)]
c = 0
for i in range(n-1,0,-1):
    if a[i] ==0 and mark[i+1]%2==1:
        c += 1
        select[i + 1] = 1
        l = 1
        r = (i + 1)
        m = math.sqrt(i+1)
        m = int(m)
        while (l <=m):
            if (i + 1) % l == 0:
                mark[l] += 1
                r = (i + 1) // l
                if l != r:
                    mark[r] += 1
            l += 1
    if a[i] and mark[i+1]%2==0:
        c+=1
        select[i + 1] = 1
        l = 1
        r = (i + 1)
        m = math.sqrt(i + 1)
        m = int(m)
        while (l <= m):
            if (i + 1) % l == 0:
                mark[l] += 1
                r = (i + 1) // l
                if l!=r:
                    mark[r] += 1
            l += 1
if a[0]==0 and mark[1]%2==1:
    c+=1
    select[1]=1
    mark[1]+=1
elif a[0]==1 and mark[1]%2==0:
    c += 1
    select[1] = 1
    mark[1] += 1
print(c)
for i in range(1,n+1):
    if select[i]:
        sys.stdout.write('{} '.format(i))

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a = list(map(int,input().split()))
select = [0 for _ in range(n+1)]
mark = [0 for _ in range(n+1)]
c = 0
for i in range(n-1,0,-1):
    if a[i] ==0 and mark[i+1]%2==1:
        c += 1
        select[i + 1] = 1
        l = 1
        r = (i + 1)
        while (l < r):
            if (i + 1) % l == 0:
                mark[l] += 1
                r = (i + 1) // l
                if l != r:
                    mark[r] += 1
            l += 1
    if a[i] and mark[i+1]%2==0:
        c+=1
        select[i + 1] = 1
        l = 1
        r = (i + 1)
        while (l < r):
            if (i + 1) % l == 0:
                mark[l] += 1
                r = (i + 1) // l
                if l!=r:
                    mark[r] += 1
            l += 1
if a[0]==0 and mark[1]%2==1:
    c+=1
    select[1]=1
    mark[1]+=1
elif a[0]==1 and mark[1]%2==0:
    c += 1
    select[1] = 1
    mark[1] += 1
print(c)
for i in range(1,n+1):
    if select[i]:
        sys.stdout.write('{} '.format(i))

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a = list(map(int,input().split()))
ans = set()
for i in range(n-1,-1,-1):
    c = 0
    for v in ans:
        if v%(i+1)==0:
            c+=1
    if a[i] ==0 and c%2==1:
        ans.add(i+1)
    if a[i] == 1 and c % 2 == 0:
        ans.add(i + 1)
ret = list(ans)
print(len(ret))
for v in ret:
    sys.stdout.write('{} '.format(v))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = set()
for i in range(n-1,-1,-1):
    c = 0
    for v in ans:
        if v%(i+1)==0:
            c+=1
    if a[i] ==0 and c%2==1:
        ans.add(i+1)
    if a[i] == 1 and c % 2 == 0:
        ans.add(i + 1)
ret = list(ans)
ret.sort()
print(len(ret))
print(*ret)

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 = sum(
            [box_list[j] for j in range(i + 1, N) if (j + 1) % (i + 1) == 0])

        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:
N = int(input())
A = list(map(int, input().split()))

def amount(num, A):
    ret = 0
    for i, a in enumerate(A):
        if (i+1) % num == 0:
            ret += a
    return ret

tmp = 0
for i in range(N-1, -1, -1):
    tmp = amount(i+1, A)
    if tmp == i:
        tmp = i
        break

print(tmp)
for i in range(1, tmp+1):
    if i % tmp == 0:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
cnt = 0
res = []
for i in range(n - 1, -1, -1):
    c = i + 1
    if (A[i] % 2 == 1):
        cnt += 1
        res.append(c)
        for k in range(1, int(c ** 0.5) + 1):
            if (c % k == 0):
                if (k != c // k):
                    A[k - 1] -= 1
                    A[c // k - 1] -= 1
                else:
                    A[k - 1] -= 1
print(cnt)
print(*res)

Submission status: Time Limit Exceeded

Solution code:
from sys import exit, stderr
from inspect import currentframe
def debug(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=stderr)
    return
N = int(input())
a = [int(_) for _ in input().split()]
b = set()
out = []
n = 0
for i in range(N-1, -1, -1):
    if a[i] == 1:
        out.append(i + 1)
        n += 1
        # print(i+1)
        for f in range(1, int((i+1)**0.5)+1):
            if (i+1)%f == 0:
                a[f-1] = 0 if a[f-1] == 1 else 1
                if f != (i+1)//f and f != 1:
                    a[(i+1)//f-1] = 0 if a[(i+1)//f-1] == 1 else 1
    debug(a)
print(n)
# print(b)
if len(out) > 0:
    for i in range(len(out)):
        print(out[i], end=" ")
    print()

Submission status: Time Limit Exceeded

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

if n<=100:
    for i in range(n):
        if i <= n//2:
            pass
        else:
            sol[n-i-1] = sum(sol[n-i-1::n-i]) % 2
else:
    for i in range(n):
        sol[n-i-1] = sum(sol[n-i-1::n-i]) % 2

a = sum(sol)
ls = ""
for i in range(n):
    if sol[i] == 1:
        ls = ls + " " + str(i+1)

print(a)
if ls != "":
    ls = ls[1:]
    print(ls)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

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

#mid = n//2 + n%2

ans = [0]*n
for i, a in enumerate(an[::-1]):

#    ta = [x for ii,x in enumerate(an[i:]) if i % (n-(ii+i)) == 0]
#    t = sum(ta)
#    print(ta,t,i,a)
#    ans[-i] = t%2

    ans[-i] = sum([x for ii, x in enumerate(an[i:]) if i % (n-(ii+i)) == 0])%2

m = sum(ans)
print(m)

if m > 0:
    print(*[x for x in ans if x >0])

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

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

#mid = n//2 + n%2

ans = [0]*n
for i, a in enumerate(an[::-1]):

    ta = [x for ii,x in enumerate(an[i:]) if i % (n-(ii+i)) == 0]
    t = sum(ta)
#    print(ta,t,i,a)
    ans[-i] = t%2

m = sum(ans)
print(m)

if m > 0:
    print(*[x for x in ans if x >0])

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

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

#mid = n//2 + n%2

ans = [0]*n
for i, a in enumerate(an[::-1]):

    ta = [x for ii,x in enumerate(an) if i % (n-ii) == 0]
    t = sum(ta)
#    print(ta,t,i,a)
    ans[-i] = t%2

m = sum(ans)
print(m)

if m > 0:
    print(*[x for x in ans if x >0])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)

N = int(input())
a = [0]+[int(i) for i in input().split()]
ret = [0] * (N+1)

def rec(i) :
    if i == N + 1 :
        return
    rec(i+1)
    s = 0
    for j in range(i, N + 1, i) :
        s ^= ret[j]
    ret[i] = s^a[i]
    
rec(1)
b = []
for i in range(1, N + 1) :
    if ret[i] :
        b.append(str(i))
print(len(b))
print(' '.join(b))

Submission status: Time Limit Exceeded

Solution code:
import sys

N=int(sys.stdin.readline().rstrip())
AList=list(map(int,sys.stdin.readline().split()))

bList=[]
for i in range(len(AList)-1, -1, -1):
  counter=0
  for b in bList:
    if b % (i+1) == 0:
      counter+=1
  if (counter % 2 == 0 and AList[i] == 0) or (counter % 2 == 1 and AList[i] == 1):
    # O.K    
    continue
  else:
    # O.K
    bList.append(i+1)

if len(bList) == 0:
    print(0)
    exit() 
else:
  print(len(bList))
  for b in bList:
    print(b)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arr = list(map(int, input().split()))
ans_list = [0] * (N)
ans = []
summ = 0
for i in range(N):
    for j in range(N-i+1,N):
        if (j % i) == 0:
            summ += ans_list[j]
    if (summ % 2) != arr[i]:
        ans_list[i] = 1
        ans.append(arr[i])

print(sum(ans))
for i in range(len(ans)):
    print(ans[i],' ', end="")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
arr = list(map(int, input().split()))
count_1 = arr.count(1)
ans_list = [0] * (N)
ans = []
summ = 0
if count_1 == 0:
    print(0)
    exit()
for i in range(N):
    for j in range(N-i+1,N):
        if (j % i) == 0:
            summ += ans_list[j]
    if (summ % 2) != arr[i]:
        ans_list[i] = 1
        ans.append(arr[i])

print(sum(ans))
for i in range(len(ans)):
    print(ans[i],' ', end="")

Submission status: Time Limit Exceeded

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

hako = [0] * (N+1)

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

        if count % 2 == a[i-1]:
            hako[i] = 0
        else:
            hako[i] = 1

print(sum(hako))

if sum(hako):
    ans = []
    for i, bin in enumerate(hako):
        if bin:
            ans.append(i)
    print(*ans)

Submission status: Time Limit Exceeded

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

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

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

b = []

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

for i in range(1,n//2+1)[::-1]:
    s = 0
    if i == 1:
        if len(b) == 0 and a[0]:
            b.append(1)
        elif len(b) % 2 != a[0]:
            b.append(1)
        break
    for j in b:
        if j % i == 0:
            s += 1
    if s % 2:
        if a[i-1] == 1:
            continue
        b.append(i)
    elif s % 2 == 0 and a[i-1] == 1:
        b.append(i)

m = len(b)
if m == 0:
    print(0)
    quit()
else:
    b.sort()
    print(m)
    for i in range(m-1):
        print(b[i],end=' ')
    print(b[-1])

Submission status: Time Limit Exceeded

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

for i in range(n):
	j = n - 1 - i
	k = (j + 1) + (j + 1)
	if k > n:
		if a[j] == 1:
			ans.append(j+1)
	else:
		count = 0
		while k <= n:
			if k in ans:
				count = count + 1
			k = k + (j + 1)
		count_01 = count % 2
		if a[j] == 0:
			if count_01 == 1:
				ans.append(j+1)
		elif a[j] == 1:
			if count_01 == 0:
				ans.append(j+1)
if not ans:
	print(0)
else:
	print(str(len(ans))+"\n" + " ".join(list(map(str,ans))))

Submission status: Time Limit Exceeded

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

for i in range(n):
	j = n - 1 - i
	k = (j + 1) + (j + 1)
	if k > n:
		if a[j] == 1:
			ans.append(j+1)
	else:
		count = 0
		while k <= n:
			if k in ans:
				count = count + 1
			k = k + (j + 1)
		count_01 = count % 2
		if a[j] == 0:
			if count_01 == 1:
				ans.append(j+1)
		elif a[j] == 1:
			if count_01 == 0:
				ans.append(j+1)
if not ans:
	print(0)
else:
	print(str(len(ans))+"\n" + " ".join(list(map(str,ans))))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B =[]
i = N-1
M = 0
while(i>=0):
    sum1=0
    j = i + i
    while (j<N):
        sum1 += 1
        j+=i
    if sum1%2!=A[i]:
        M+=1
        B.append(i)
    i-=1
B.reverse
print(M)
for s in B:
    print(s,end=" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = []
b = 0
for i in range(n):
	j = n - 1 - i
	if b == 0:
		if a[j] == 1:
			ans.append(j+1)
			c = j + 1
			b = 1
	elif b == 1 and j + 1 > c / 2:
		if a[j] == 1:
			ans.append(j+1)
	else:
		k = (j + 1) + (j + 1)
		count = 0
		while k <= n:
			if k in ans:
				count = count + 1
			k = k + (j + 1)
		count_01 = count % 2
		if a[j] == 0:
			if count_01 == 1:
				ans.append(j+1)
		elif a[j] == 1:
			if count_01 == 0:
				ans.append(j+1)
if not ans:
	print(0)
else:
	print(str(len(ans))+"\n" + " ".join(list(map(str,ans))))

Submission status: Time Limit Exceeded

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

total = 0
b = set()
for i in range(N):
    tmpBall = 0
    for j in range(N - i, N):
        if (j + 1) % (N - i) == 0 and b.__contains__(j + 1):
            tmpBall = tmpBall + 1
    if tmpBall % 2 != a[N - i - 1]:
        total = total + 1
        b.add(N - i)

print(total)
for k in b:
    print(k)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_a = list(map(int, input().split()))
ans_list = []
for n in range(N, 0, -1):
  if N//n == 1 and list_a[n-1] == 1:
    ans_list.append(n)
  else:
    sum_ = 0
    for j in range(N):
      if j%n == 0 and j//2 >1:
        sum_ += list_a[j]
    if sum_%2 != list_a[n-1]:
      ans_list.append(n)
b = len(ans_list)
print(b)
if b !=0:
  for i in ans_list:
    print(i)

Submission status: Time Limit Exceeded

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

for i in range(2**N):
  temp = list(format(i,"0"+str(N)+'b'))
  temp1 = list(map(int, temp))
  for k in range(1,N+1):
    if sum(temp1[k-1::k])%2 == A[k-1]:
        pass
    else:
        break
  else:
    print(sum(temp1))
    anslist = []
    for i in range(N):
        if temp1[i] == 1:
          anslist.append(i+1)
    if anslist == []:
      exit()
    else:
      print(*anslist)
      exit()

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


num = int(N // 2 + 1)
cnt = {}
for i in range(1, N + 1):
    cnt[i] = 0
A.reverse()
B = []

for i, a in enumerate(A):
    i = N - i
    if i >= num:
        if a == 1:
            for p in make_divisors(i):
                cnt[p] = (cnt[p] + 1) % 2
            B.append(i)
    else:
        if cnt[i] != a:
            for p in make_divisors(i):
                cnt[p] = (cnt[p] + 1) % 2
            B.append(i)

print(len(B))
B = list(map(str, B))
print(' '.join(B))

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
import numpy as np

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

num_list = []

i = n
while i > math.ceil(n/2):
  if a[i-1] == 1:
    num_list.append(i)
  i -= 1

i = math.ceil(n/2)
while i > 0:
  count = 0
  if a[i-1] == 1:
    for x in num_list:
      if x % i == 0:
        count += 1

    if count % 2 == 0:
      num_list.append(i)
  else:
    for x in num_list:
      if x % i == 0:
        count += 1

    if count % 2 == 1:
      num_list.append(i)
  i -= 1

l = (len(num_list))

if l == 0:
  print(0)
else:
  print(l)
  print(' '.join([str(n) for n in num_list]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_a = list(map(int, input().split()))
ans_list = []
for n in range(N, 0, -1):
  if N//n == 1 and list_a[n-1] == 1:
    ans_list.append(n)
  else:
    sum_ = sum([list_a[j] for j in range(N) if j%n == 0 and j//n > 1])
    if sum_%2 != list_a[n-1]:
      ans_list.append(n)
b = len(ans_list)
print(b)
if b !=0:
  for i in ans_list:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

def add_ball(idx):
    add_list = []
    for j in range(1, int(math.sqrt(idx))+1):
        if idx%j == 0:
            add_list.append(j)
            if j != idx//j:
                add_list.append(idx//j)
    for k in add_list:
        b_list[k] += 1

if __name__ == "__main__":
    input = sys.stdin.readline

    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0] * (n+1)
    ans_list = []
    for a, i in zip(reversed(a_list), range(n, 0, -1)):
        if a != b_list[i]%2:
            ans_list.append(i)
            add_ball(i)
    cnt = len(ans_list)
    ans_list.sort()
    print(cnt)
    if cnt > 0:
        print(' '.join(map(str, ans_list)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_a = list(map(int, input().split()))
ans_list = []
for i in range(N):
  n = N-i
  if N//n == 1 and list_a[n-1] == 1:
    ans_list.append(n)
  else:
    sum_ = sum([list_a[j] for j in range(N) if j%n == 0 and j//n > 1])
    if sum_%2 != list_a[n-1]:
      ans_list.append(n)
b = len(ans_list)
print(b)
if b !=0:
  for i in ans_list:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()] 
ls = np.array(a)

st = int(n/2)
ans =  [i+st+1 for i, n in enumerate(a[st:]) if n ==1] 
for ind in range(st, 0, -1):
    tmp = list(range(2*ind-1, n, ind))
    s = ls[tmp].sum()%2
    if a[ind-1] == s:
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        ans.append(ind)
        
print(sum(ls))
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()] 
ls = np.array(a)

st = int(n/2)
ans = list(np.where(ls[st:]==1)[0] + 1 + st)
for ind in range(st, 0, -1):
    tmp = list(range(2*ind-1, n, ind))
    s = ls[tmp].sum()%2
    if a[ind-1] == s:
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        ans.append(ind)
        
print(sum(ls))
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()] 
ls = np.array(a)

ans = []
for ind in range(n, 0, -1):
    tmp = list(range(2*ind-1, n, ind))
    s = ls[tmp].sum()%2
    if a[ind-1] == s:
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        ans.append(ind)
        
print(sum(ls))
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
al=list(map(int,input().split()))
ans=[]
tl=[0]*n
for i in range(n,0,-1):
    if tl[i-1]%2^al[i-1]:
        ans.append(i)
        for j in range(1,int(i**0.5)+1):
            if i%j==0:
                tl[j-1]^=1
                if j**2==i:
                    continue
                tl[i//j-1]^=1
print(len(ans))
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 2  # type: int


import math
import collections


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


def solve(N: int, a: "List[int]"):
    b = [0]*N
    for i in range(N-1, -1, -1):
        if b[i] % MOD == a[i]:
            b[i] = 0
        else:
            b[i] = 1
            for d in make_divisors(i+1):
                if d != i+1:
                    b[d-1] += 1
    c = [i+1 for i, val in enumerate(b) if val % 2 > 0]
    print(len(c))
    if len(c) != 0:
        print(*c, sep=" ")
    return


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())
a = list(map(int,input().split()))
ball = []
s = 0

for i in range(n-1, (n-1)//2, -1):
    ball.insert(0, a[i])
for i in range((n-1)//2, -1, -1):
    for j in range(len(ball)):
        if (j+1) % (i+1) == 0:
            s += ball[j]

    s = s % 2
    if a[i] == s:
        ball.insert(0, 0)
    else:
        ball.insert(0, 1)
ans = ""
count = 0
for i in range(n):
    if ball[i] == 1 and i < n-1:
        ans += str(i+1) + ""
        count += 1
    elif ball[i] == 1 and i==n-1:
        ans += str(i+1)
        count += 1
if count > 0:
    print(count)
    print(ans)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
def calc(N, a):
    if (N == 1):
        if (a[0] == 0):
            return '0'
        else:
            return '1\n1'
    else:
        w = N // 2
        b = list(a)
        for i in range(w - 1, -1, -1):
            start = [j for j in range(i + 1, i * 2 + 2) if j % (i + 1) == 0][0]
            for j in range(i + 1, N, i + 1):
                b[i] += b[j]
            b[i] = b[i] % 2
        result = []
        for i in range(N):
            if (b[i] == 1):
                result += [str(i + 1)]
        s = str(len(result)) + '\n'
        s += ' '.join(result)
        return s


N = int(input())
a = [int(s) for s in input().split(' ')]
print(calc(N, a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()] 
ls = np.array(a)

for ind in range(int(n/2), 0, -1):
    tmp = list(range(2*ind-1, n, ind))
    s = ls[tmp].sum()%2
    if a[ind-1] == s:
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        
print(ls.sum())
ans = np.where(ls==1)[0] + 1
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 2  # type: int


import math
import collections


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


def solve(N: int, a: "List[int]"):
    b = [0]*N
    for i in range(N-1, -1, -1):
        if b[i] % MOD == a[i]:
            b[i] = 0
        else:
            b[i] = 1
            for d in make_divisors(i+1)[:-1]:
                b[d-1] += 1

    c = [i+1 for i, val in enumerate(b) if val % 2 > 0]
    print(len(c))
    if len(c) != 0:
        print(*c, sep=" ")
    return


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:
# -*- coding: utf-8 -*-
N=int(input())
a=list(map(int,input().split()))
seta=set()

for i in range(N//2,N):
    if a[i]==1:
        seta.add(i+1)
        
for i in range(3,N+1):
    if N//i+1<N//(i-1):
        for j in range(N//i+1,N//(i-1)+1):
            m=2
            asum=0
            while j*m<=N:
                if j*m in seta:
                    asum=asum+1
                m=m+1
            if asum%2!=a[j-1]:
                seta.add(j)
    else:
        j=N//i+1
        m=2
        asum=0
        while j*m<=N:
            if j*m in seta:
                asum=asum+1
            m=m+1
        if asum%2!=a[j-1]:
            seta.add(j)

asum=0
for n in range(2,N+1):
    if n in seta:
        asum=asum+1
if asum%2!=a[0]:
        seta.add(1)

print(len(seta))
if len(seta)!=0 and len(seta)==1:
    print(list(seta)[0])
elif len(seta)!=0:
    print(" ".join(list(seta)))