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
sys.setrecursionlimit(4100000)

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

import numpy as np


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 = np.zeros(N, dtype=bool)

    for i_box in reversed(range(N)):
        j_arr = np.arange(i_box + 1, N)
        suma = np.sum(box_list[i_box + 1:][np.mod(j_arr + 1, i_box + 1) == 0])
        r = int(suma) % 2
        if r != a_list[i_box]:
            box_list[i_box] = 1

    s = np.sum(box_list)
    print(int(s))

    if s > 0:
        print(' '.join([str(i_box + 1) for i_box in np.arange(N)[box_list]]))


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:
import numpy as np


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

B = np.zeros(N)
R = []
I = np.arange(1, N+1)

for i in I[::-1]:
    if B[i-1] % 2 != A[i-1]:
        B[((i % I) == 0)] += 1
        R.append(i)

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ls=list(map(int,input().split()))
count_ls=[0]*n
answers=[]
m=0

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.remove(n)
    return divisors

for i in range(n,0,-1):
    plus_flag=False
    idx=i-1
    if count_ls[idx]%2!=ls[idx]:
        plus_flag=True
        m+=1
        answers.append(i)
    if plus_flag:
        divisors=set(make_divisors(i))
        for j in divisors:
            j_idx=j-1
            count_ls[j_idx]+=1

print(m)
if m:
    print(" ".join(list(map(str,answers))))

Submission status: Time Limit Exceeded

Solution code:
import sys

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

a.insert(0, -1)

env = [0] * (n+1)
hako = [0] * (n+1)
ind = []

for _ in range(n):
    i = n - _
    if a[i] != env[i]:
        hako[i] = 1
        ind.append(str(i))
        yakusuu = make_divisors(i)
        for j in yakusuu:
            if env[j] == 0:
                env[j] = 1
            else:
                env[j] = 0

goukei = sum(hako)
print(goukei)
if ind == []:
    sys.exit()
mojiretu = ' '.join(ind)
print(mojiretu)

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)
numbers = np.arange(1,  N+1)
M = 0
outputs = []

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

print(M)
if M != 0:
    outputs.sort()
    outputs = [str(x) for x in outputs]
    print(' '.join(outputs))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = list(map(int, input().split()))
for x in list(itertools.product((0, 1), repeat=N))[::-1]:
    flag = True
    # print(x)
    for i in range(1, N+1):
        tmp = list(x)
        tmp = tmp[i-1::i]
        if sum(tmp) % 2 != A[i-1]:
            flag = False
            break
    if flag:
        total = sum(x)
        if total == 0:
            print(0)
            exit()

        print(total)
        for i, e in enumerate(x):
            if e == 1:
                print(i+1)
        exit()
print("-1")

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+1)/2:
        b[i]=a[i]
    else:
        tmp_list=[s for s,ind in zip(b,range(N)) if ind%(i+1)==0]
        b[i] = abs(a[i] - sum(tmp_list) )
print(sum(b))
if sum(b) > 0:
    c = [1 for s,ind in zip(b,range(N)) if s==1]
    print(" ".join(map(str,c)) )

Submission status: Time Limit Exceeded

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

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


ans = []
cnt = [0]*n
for i in reversed(range(n)):
    if a[i] != cnt[i]%2:
        ans.append(i+1)
        temp = make_divisors(i+1)
        #print(temp)
        for j in temp:
            cnt[j-1] += 1

print(len(ans))
out = ""
if len(ans) != 0:
    for i in ans:
        out += str(i)+" "
    print(out[0:len(out)-1])

Submission status: Time Limit Exceeded

Solution code:
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
N = int(input())
a = list(int(i) for i in input().split())
ans_list = []
ans = 0
for i in range(N):
	if a[N-1-i] == 1:
		ans += 1
		ans_list.append(N-i)
		chk = make_divisors(N-i)
		for j in range(len(chk)):
			a[chk[j]-1] = (1+a[chk[j]-1])%2
print(ans)
if len(ans_list) != 0:
	print(*ans_list)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ls=list(map(int,input().split()))
count_ls=[0]*n
answers=[]
m=0

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.remove(n)
    return divisors

for i in range(n,0,-1):
    plus_flag=False
    idx=i-1
    if count_ls[idx]%2!=ls[idx]:
        plus_flag=True
        m+=1
        answers.append(i)
    if plus_flag:
        divisors=make_divisors(i)
        for j in divisors:
            j_idx=j-1
            count_ls[j_idx]+=1

print(m)
if m:
    print(" ".join(list(map(str,answers))))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy

N = int(input())  
a = np.array(input().split(), dtype=np.int32)
b = copy.deepcopy(a)
M = np.arange(N) + 1
    
for i in np.arange(N // 2)[::-1]:
    B = b[np.where(M % (i+1) == 0)]
    if np.sum(B) % 2  == 0:
        b[i] = 0
    else:
        b[i] = 1
        
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:
import sys
n = int(input())
a = list(map(int, input().split()))

for i in range(2**n):
    b = [0]*n
    for j in range(n):
        if ((i >> j) & 1):
            b[j] = 1

    
    if all(sum(b[j::j+1])%2 == a[j] for j in range(n)):
        print(sum(b))
        for k in range(n):
            if b[k] == 1:
                print(k+1,end="")
        print()
        sys.exit()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque
import sys

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


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

    return divisors


def main():
    N = int(input())
    # A = [
    #     int(input())
    #     for _ in range(N)
    # ]
    A = [int(a) for a in input().split()]

    res_c = 0
    res1 = []
    bucket = [0] * (N + 1)

    for i in reversed(range(N)):
        k = i + 1
        if i * 2 + 2 > N:
            if A[i] == 1:
                res_c += 1
                res1.append(k)
                for di in d(k):
                    bucket[di] += 1
            continue
        if k == 1:
            if res_c % 2 != A[i]:
                res_c += 1
                res1.append(k)
            break

        if bucket[k] % 2 != A[i]:
            res_c += 1
            res1.append(k)
            for di in d(k):
                bucket[di] += 1
    print(res_c)
    print(*res1)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    result = [0 for _ in range(N)]
    for i, a in enumerate(As[::-1]):
        num = N - i
        idx = num - 1
        if N // num < 2:
            result[idx] = a
        else:
            sum_ = sum([x for i, x in enumerate(result) if idx % (i + 1) == 0])
            if sum_ % 2 == 1:
                result[idx] = 1 if a == 0 else 0
            else:
                result[idx] = 0 if a == 0 else 1
    print(len([x for x in result if x == 1]))
    for i, x in enumerate(result):
        if x == 1:
            print(i + 1, end=' ')


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import defaultdict
from heapq import heappush, heappop
from math import ceil


def djkstra_adj_list(adj_list, src):
    dist = defaultdict(lambda: np.inf)
    dist[src] = 0

    prev = defaultdict(lambda: None)

    queue = []
    heappush(queue, (dist[src], src))

    while len(queue) > 0:
        dist_u, u = heappop(queue)
        vs = adj_list[u]
        for v, weight in vs:
            alt = dist_u + weight
            if alt < dist[v]:
                dist[v] = alt
                prev[v] = u
                heappush(queue, (alt, v))

    return dist, prev


def djkstra_adj_mat(adj_mat, src):
    dist = defaultdict(lambda: np.inf)
    dist[src] = 0

    prev = defaultdict(lambda: None)

    queue = []
    heappush(queue, (dist[src], src))

    while len(queue) > 0:
        dist_u, u = heappop(queue)
        vs = np.argwhere(adj_mat[u] > 0).flatten()
        for v in vs:
            weight = adj_mat[u, v]
            alt = dist_u + weight
            if alt < dist[v]:
                dist[v] = alt
                prev[v] = u
                heappush(queue, (alt, v))

    return dist, prev


def main():

    N = int(input())
    a_arr = list(map(int, input().split()))
    a_arr = np.array(a_arr, dtype=np.int)

    boxes = np.zeros(N, dtype=np.int)

    boxes[N//2+1-1:] = a_arr[N//2+1-1:]

    for i in range(N//2, 0, -1):
        boxes[i-1] = (np.sum([boxes[np.arange(i * 2, N+1, i)-1]]) + a_arr[i-1]) % 2

    # print(boxes)
    M = int(np.sum(boxes == 1))
    print(M)
    j = 0
    b_arr = np.argwhere(boxes == 1)
    for j in range(M):
        if j == M - 1:
            print(int(b_arr[j]) + 1)
        else:
            print(int(b_arr[j]) + 1, end=' ')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def is_ok(pat):
    ok = True
    for i in range(1,N+1):
        sum = 0
        for j in range(i,N+1,i):
#            print(i,j)
            sum += int(pat[j-1])
#        print("i"+str(i))
        if A[i-1] != sum % 2:
            ok = False
            break
    
    return ok

is_end = False
for i in range(2**N):
    bin = format(i,'0'+str(N)+'b')
#    print(bin)
    ok = is_ok(bin)
    if ok:
        is_end=True
        M = 0
        ans_list = []
        for i,b in enumerate(bin):
            b = int(b)
            M += b
            if b != 0:
                ans_list.append(i+1)
        print(M)

        for a in ans_list:
            print(str(a)+' ')
        break

if is_end == False:
    print('-1')

Submission status: Time Limit Exceeded

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

for i, ai in enumerate(a,1):
  for j in range(1, N+1):
    if j % i == 0:
      b[i] += ai

b = [i for i, bi in enumerate(b) if bi % 2 == 1]
M = b.count(1)
if M == 0:
  print(0)
else:
  print(M)
  print(' '.join(map(str, b)))

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_box in reversed(range(N)):
        suma = 0
        for j_devided in range(i_box + 1, N):

            num_mut = 2
            while (True):
                prod = (i_box + 1) * num_mut
                if prod > j_devided + 1:
                    break
                if prod == j_devided + 1:
                    suma += box_list[j_devided]

                num_mut += 1

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

    s = sum(box_list)
    print(s)

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


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()))
M = - 1
bgood = []
for n in range(2 ** (N + 1)):
  if M > -1:
    break
  b = [0] * N
  m = n
  for j in range(N):
    b[j] = m % 2
    m = m // 2
  for k in range(N):
    sum = 0
    for l in range(N):
      if (l + 1) % (k + 1) == 0:
        sum = sum + b[l]
    if sum % 2 != a[k]:
      break
    if k == N - 1:
      M = 0
      bgood = b
      for p in b:
        M = M + p
print(M)
if M > -1:
  for q in range(M):
    if bgood[q] == 1:
      print(q + 1, end = ' ')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=[ -1 for i in range(N) ]

p1=N
acount=0
astr=''
for i in range(p1):
  num=p1-i-1
  j=2
  count=0
  while(True):
    if (num+1)*j>N:break
    count+=ans[(num+1)*j-1]
    j+=1
    if (num+1)*j>N:break
  ans[num]=abs(count%2-A[num])
  if ans[num]==1:
    acount+=1
    astr=' '+str(num+1)+astr

print(acount)
print(astr[1:])

Submission status: Time Limit Exceeded

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

ball = [0] * N


if a[-1] == 1:
        ball[-1] = 1

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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(int(math.sqrt(N-i))):
                if (N-i)%(j+1) == 0:
                    a[j] = not a[j]
                    if j != int((N-i)/(j+1))-1:
                        a[int((N-i)/(j+1))-1] = not a[int((N-i)/(j+1))-1]

    print(M)
    for i in b:
        print(i, end=' ')

Submission status: Time Limit Exceeded

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


import numpy as np


def solv(m, a):
    boxs = np.zeros(m, dtype=np.uint16)

    for i in range(m, 0, -1):
        idx = np.arange(i+i-1, m, i)
        s = np.sum(boxs[idx])
        boxs[i-1] = (s + a[i-1]) % 2

    return boxs


if __name__ == '__main__':

    m = int(input())
    a = np.array(list(map(int, input().split())), dtype=np.uint16)

    ans = solv(m, a)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = [int(i) for i in input().split()]
A = np.array(A)
B = np.zeros(N)
list_B = [0] * N

for i in range(N)[::-1]:
  if A[i] != (np.sum(B[i::i+1]) % 2):
    B[i] = 1
    list_B[i] = i + 1

print(int(np.sum(B)))
list_B = ' '.join([str(a) for a in [i for i in list_B if i != 0]])
print(list_B)

Submission status: Time Limit Exceeded

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

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

for i in reversed(range((n//2))):
    k = 0
    for j in range(len(b)):
        if b[j]%(i+1) == 0:
            k += 1
    if a[i] != k%2:
        b=[i+1] + b

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

Submission status: Time Limit Exceeded

Solution code:
import math


def nontrivial_divisors(x):
	for i in range(1, math.floor(math.sqrt(x)) + 1):
		d, m = divmod(x, i)
		if m == 0:
			if i != x:
				yield i
			if d != x:
				yield d


def solve(n, qs):
	ps = [0] # sent.
	ps.extend(qs)
	balls = [0] * (n + 1)
	vals = [0] * (n + 1)
	divs = [set(nontrivial_divisors(i)) for i in range(n + 1)]
	first = n // 2 + 1
	last = n
	while True:
		for i in range(first, last + 1):
			if vals[i] % 2 != ps[i]:
				balls[i] += 1
				vals[i] += 1
				for j in divs[i]:
					vals[j] += 1
		if first == 1:
			break
		last = first - 1
		first = last // 2 + 1
	for i in range(1, n + 1):
		if vals[i] % 2 != ps[i]:
			return None
	else:
		bs = [b for b in range(1, n + 1) if balls[b]]
		m = len(bs)
		return m, bs
	

def main():
	n = int(input())
	qs = [int(q) for q in input().split()]
	res = solve(n, qs)
	if res is None:
		print(-1)
	else:
		m, bs = res
		print(m)
		print(*bs)


if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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


import numpy as np


def solv(m, a):
    boxs = np.zeros(m, dtype=np.int)

    for i in range(m, 0, -1):
        idx = np.arange(i+i-1, m, i)
        s = np.sum(boxs[idx])
        boxs[i-1] = (s + a[i-1]) % 2

    return boxs


if __name__ == '__main__':

    m = int(input())
    a = np.array(list(map(int, input().split())), dtype=np.int)

    ans = solv(m, a)

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
c=[]
cnt=0
for i in range(1,N+1)[::-1]:
  if len([x for x in c if x%i==0])%2 != a[i-1]:
    a[i-1]=1
    c.append(i)
    cnt+=1
print(cnt)
if len(c)>0:
  print(*c,sep='\n')

Submission status: Time Limit Exceeded

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

B = [0 for i in range(N)]
R = []
I = list(range(1, N+1))

for i in I[::-1]:
    if B[i-1] % 2 != A[i-1]:
        for j in I[:i+1]:
            if i % j == 0:
                B[j-1] += 1
                if i == j:
                    R.append(i)
R.sort()
print(len(R))
if R:
    print(' '.join(map(str, R)))

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
    if num > N / 2:
        if a == 1:
            M += 1
            outputs.append(num)
            boxes[num-1] = 1
    else:
        idxs = np.arange(num,  N+1, num) - 1
        S = boxes[idxs].sum()
        if S % 2 != a:
            M += 1
            outputs.append(num)
            boxes[num-1] = 1
        # print(num, idxs+1, S, boxes)

print(M)
if M != 0:
    outputs.sort()
    outputs = [str(x) for x in outputs]
    print(' '.join(outputs))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=[ -1 for i in range(N) ]

p1=int(N/2)
ans=ans[0:p1]+A[p1:]

for i in range(p1):
  num=p1-i-1
  j=2
  count=0
  while(True):
    count+=ans[(num+1)*j-1]
    j+=1
    if (num+1)*j>N:break
  ans[num]=abs(count%2-A[num])
  
count=0
astr=''
for i in range(N):
  if ans[i]==1:
    count+=1
    astr=astr+' '+str((i+1))
print(count)
print(astr[1:])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
al=list(map(int,input().split()))
ac=0
ans=set()
for i in range(n,0,-1):
    t=sum([1 for a in ans if a%i==0])
    if t%2!=al[i-1]:
        ac+=1
        ans.add(i)
print(ac)
if ac>0:
    print(' '.join(map(str,ans)))

Submission status: Time Limit Exceeded

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

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

for i in range(n//2, 0, -1):
  inlist = 0
  for ans in ans_list:
    if ans%i == 0:
      inlist += 1
  if inlist % 2 != a[i - 1]:
    ans_list.append(i)
  
if len(ans_list) > 0:
  print(len(ans_list))
  answer = ''
  for ans in ans_list:
    answer += str(ans) + ' '

  print(answer.rstrip(' '))
  
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
B = [0] * n
ansList = []

def makeList(num):
    start = num + 1
    mul = n // start
    return [start * j - 1 for j in range(1, mul+1)]


def makeRes(indices):
    flag = 0
    for elm in indices:
        if B[elm] == 1:
            flag = (flag + 1) % 2
    return flag


for i in range(n-1, -1, -1):
    if i + 1 >  n / 2:
        if A[i] == 1:
            B[i] = 1
            ans += 1
            ansList.insert(0, i+1)
    else:
        indices = makeList(i)
        # print(indices)
        res = makeRes(indices)
        # print(res)
        if A[i] != res:
            B[i] = 1
            ans += 1
            ansList.insert(0, i+1)

print(ans)

if ans != 0:
    print(*ansList)

Submission status: Time Limit Exceeded

Solution code:
def sum_mult(a, m):
    return sum(filter(lambda i: i % m == 0, a))


n = int(input())
a = list(map(lambda x: int(x), input().split()))
c = [0] * n

for i in range(1, n+1):
    s = sum_mult(a, i)
    c[i-1] = s % 2


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy

N = int(input())  
a = np.array(input().split(), dtype=np.int64)
b = copy.deepcopy(a)
M = np.arange(N) + 1
    
for i in np.arange(N // 2)[::-1]:
    A = a[np.where(M % (i+1) == 0)]
    if (np.sum(A) + a[i]) % 2  == 0:
        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())
lst = [int(s) for s in input().split()]
ans=[0]*N
result=[]
def divls(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
for i in range(N):
  n=N-1-i
  x=lst[n]
  y=ans[n]
  if(x!=y):
    result.append(n+1)
    divisors=divls(n+1)
    for j in range(len(divisors)):
      ans[divisors[j]-1]=1-ans[divisors[j]-1]
result.sort()
print(len(result))
if (len(result)!=0):
  print(' '.join(map(str, result)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(map(lambda x: int(x),input().split()))
balls=np.zeros(N+1)
#print(balls)
#print(A)
balls[N//2+1:] = A[N//2:]
num = np.array(list(range(1,N+1)))

for i in range(N//2,0,-1):
  #print(i)
  idx = num[np.where(num%i==0)]
  #print(balls[idx])
  #print(np.sum(balls[idx]))
  #print(np.sum(balls[idx])%2)
  balls[i] = (np.sum(balls[idx])+A[i-1])%2
#print(balls[1:])

idx_ans = np.where(balls==1)[0]
#print(idx_ans)
idx_ans = list(map(lambda x: str(x),idx_ans))
print(len(idx_ans))
#print(idx_ans)
if len(idx_ans)!=0:
    print(' '.join(idx_ans))

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc134/tasks/abc134_d
import sys
input = sys.stdin.readline

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

b = [0] * n
for i in reversed(range(1, n + 1)):
    s = 0
    for j in range(1, n + 1):
        if j % i == 0 and j != i:
            s += a[j - 1]
    
    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:
N = int(input())
box = list(map(int,input().split()))
li = []
for i in reversed(range(1,N+1)):
    count = 0
    for j in range(i,N+1):
        if j%i == 0 and box[j-1] == 1:
            if not j in li:
                count += 1
    if count % 2 == 1:
        li.append(i)
if li == []:
    print(0)
else:
    print(len(li))
    for i in li:
        print(i, end='')

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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 np.array(divisors)

N = int(input())
a = np.array(list(map(int, input().split()))).astype(bool)
b = np.zeros((N), dtype=bool)

for i in np.arange(1, N+1)[::-1]:
    x = a[i - 1]
    list_div = make_divisors(i)
    if x:
        b[list_div - 1] = np.array([not j for j in b[list_div - 1]])

c = sum(b)
print(c)

d = []
if c:
    for i, _ in enumerate(b):
        if _:
            d.append(i + 1)
    print(*d)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
c=[]
cnt=0
for i in range(1,N+1)[::-1]:
  if sum([x for x in b if x%i==0])%2 != a[i-1]:
    a[i-1]=1
    c.append(i)
    cnt+=1
print(cnt)
if len(c)>0:
  print(*c,sep='\n')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
al=list(map(int,input().split()))
ac=0
ans=set()
for i in range(n,0,-1):
    t=0
    for j in ans:
        if j%i==0:
            t+=1
    if t%2!=al[i-1]:
        ac+=1
        ans.add(i)
print(ac)
if ac>0:
    print(' '.join(map(str,ans)))

Submission status: Time Limit Exceeded

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

ans_list = []
for i in range(n, 0, -1):
  inlist = 0
  for ans in ans_list:
    if ans%i == 0:
      inlist += 1
  if inlist % 2 != a[i - 1]:
    ans_list.append(i)
  
if len(ans_list) > 0:
  print(len(ans_list))
  answer = ''
  for ans in ans_list:
    answer += str(ans) + ' '

  print(answer.rstrip(' '))
  
else:
  print(0)

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 i*j in ans:
                    c += 1
            else:
                break

        if A[i-1] == 0:
            if c % 2 == 1:
                ans.append(i)
        else:
            if c % 2 == 0:
                ans.append(i)

    print(len(ans))
    if len(ans):
        print(" ".join([str(i) for i in 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())
a = list(map(int, input().split()))
dp = [0] * (N + 1)
for i in range(N, 0, -1):
  #print(i)
  if i > N // 2:
    dp[i] = a[i - 1]
  else:
    j = 2
    while i * j <= N:
      dp[i] = dp[i] ^ dp[i * j]
      j += 1
    dp[i] = dp[i] ^ a[i - 1]
M = 0
res2 = ""
#print(dp)
for i, v in enumerate(dp):
  if v == 1:
    M += 1
    res2 += str(i) + " "
print(M)
print(res2)