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:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
totals=[0]*n


def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


for i in range(n-1,-1,-1):
    if totals[i]%2==a[i]:
        continue
    else:
        ans[i]+=1
        arr=make_divisors(i+1)

        for num in arr:
            totals[num-1]+=1

cnt=ans.count(1)

print(cnt)
if cnt!=0:
    b=[]
    for j in range(n):
        if ans[j]!=0:
            b.append(j+1)

    print(*b)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
a = list(map(int, input().split()))
b = deque()
ans = 0

for i in range(N):
  t = N-1-i
  k = N-i
  s = 0
  while k-1 < N:
    if k in b:
      s += 1
    k += t+1
  if (a[t]+s) % 2 == 1:
    b.appendleft(t+1)
    ans += 1
    
print(ans)
print(' '.join(map(str, b)))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
a = list(map(int, input().split()))
b = deque()
ans = 0

for i in range(1, N):
  t = N-1-i
  k = N-i
  s = 0
  while k-1 < N:
    if k in b:
      s += 1
    k += t+1
  if (a[t]+s) % 2 == 1:
    b.appendleft(t+1)
    ans += 1
    
if (a[0]+len(b)) % 2 == 1:
  b.appendleft(1)
  ans += 1
    
print(ans)
print(' '.join(map(str, b)))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
a = list(map(int, input().split()))
b = deque()
ans = 0

for i in range(N):
  t = N-1-i
  s = 0
  while t < N:
    if t+1 in b:
      s += 1
    t += N-i
  if (a[N-1-i]+s) % 2 == 1:
    b.appendleft(N-i)
    ans += 1
    
print(ans)
print(' '.join(map(str, b)))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    input = stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    p = []
    for i in reversed(range(n)):
        if a[i]:
            p.append(i + 1)
            u = 1
            v = i + 1
            while u * u <= v:
                if v % u == 0:
                    a[u - 1] ^= 1
                    if u != v // u:
                        a[v // u - 1] ^= 1
                u += 1
    if len(p) > 0:
        print(len(p))
        print(*p)
    else:
        print(0)
main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

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

print(sum(a))
for i in ans:
  if i==1:print(i)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

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

print(sum(a))
for i in ans:
  if i==1:print(i)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]
cnt=0

for i in range(n-1,-1,-1):
  now=0
  j=i+1
  end=2
  while(end*j<=n-1):
    if (end*j+1)%(i+1)==0:
      now+=ans[j]
    j+=1
  

  if now%2==0 and a[i]==1:
    ans[i]=1
    cnt+=1

  elif now%2==1 and a[i]==0:
    ans[i]=1
    cnt+=1

print(cnt)
for i in ans:
  if i==1:print(i)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]
cnt=0

for i in range(n-1,-1,-1):
  now=0
  j=i+1
  end=2
  while(end*j<=n-1):
    if (end*j+1)%(i+1)==0:
      now+=ans[j]
    j+=1
  
  if now%2==0 and a[i]==0:
    ans[i]=0
    continue

  elif now%2==0 and a[i]==1:
    ans[i]=1
    cnt+=1
    continue

  elif now%2==1 and a[i]==1:
    ans[i]=0
    continue
  else:
    ans[i]=1
    cnt+=1
    continue
print(cnt)
for i in ans:
  if i==1:print(i)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]
cnt=0

for i in range(n-1,-1,-1):
  now=0
  j=i+1
  while(j<=n-1):
    if (j+1)%(i+1)==0:
      now+=ans[j]
    j+=1
  
  if now%2==0 and a[i]==0:
    ans[i]=0
    continue

  elif now%2==0 and a[i]==1:
    ans[i]=1
    cnt+=1
    continue

  elif now%2==1 and a[i]==1:
    ans[i]=0
    continue
  else:
    ans[i]=1
    cnt+=1
    continue
print(cnt)
for i in ans:
  if i==1:print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
ls = list(map(int,input().split()))
for k in range(2**n):
    a = [0]*n
    for l in range(n):
        if (k>>l)&1:
            a[l] += 1
    p = 0
    for i in range(n):
        di = a[i::i+1]
        m = sum(di)
        if m % 2 != ls[i]:
            p = 1
            break
    if p == 0:
        new = []
        for t in range(len(a)):
            if a[t] == 1:
                new.append(t+1)
        print(sum(a))
        if sum(a) != 0:
            print(*new)
        sys.exit()
print(-1)

Submission status: Time Limit Exceeded

Solution code:
kosuu = int(input())
dp = list(map(int,input().split()))
ans = []
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
for i in range(kosuu):
	hako = kosuu - i
	if dp[hako-1] == 1:
		for j in make_divisors(hako)[:-1]:
			dp[j-1] ^= 1
		ans.append(hako)
print(len(ans))
finalans = ''
for i in ans[::-1]:
	finalans += str(i) + ' '
print(finalans[:-1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n-1,-1,-1):
    temp=0
    for j in range(i,n): temp+=ans[j]
    if a[i]!=temp%2: ans[i]=1
print(sum(ans))                                 
for i in range(n):
    if ans[i]==1: print(i+1,end=" ")

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def divisor(n):
    i = 1
    d = []
    while i * i <= n:
        if n % i == 0:
            d.append(i)
            if i * i != n:
                d.append(n // i)
        i += 1
    return d


def solve(N, A):
    ans = set()
    for i in range(N, 0, -1):
        if A[i-1] == 1:
            ans.add(i)
            for d in divisor(i):
                A[d-1] ^= 1
    print(len(ans))
    print(*ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def divisor(n):
    i = 1
    d = []
    while i * i <= n:
        if n % i == 0:
            d.append(i)
            if i * i != n:
                d.append(n // i)
        i += 1
    return d


def solve(N, A):
    ans = []
    for i in range(N, 0, -1):
        if A[i-1] == 1:
            ans += [i]
            for d in divisor(i):
                A[d-1] ^= 1
    print(len(ans))
    print(*ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
def main():
    def add_divisors(n, d):
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                d[i] += 1
                if i != n // i:
                    d[n // i] += 1
    n = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    ans = []
    for i, a in enumerate(A[::-1]):
        i = n - i
        if d[i] % 2 != a:
            ans.append(str(i))
            add_divisors(i, d)
    print(len(ans))
    print(' '.join(ans))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    def add_divisors(n, d):
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                d[i] += 1
                if i != n // i:
                    d[n // i] += 1
    n = int(input())
    A = list(map(int, input().split()))
    d = {}
    ans = []
    for i in range(1, n + 1):
        d[i] = 0
    for i, a in enumerate(A[::-1]):
        i = n - i
        if d[i] % 2 != a:
            ans.append(str(i))
            add_divisors(i, d)
    print(len(ans))
    print(' '.join(ans))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    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(map(int, input().split()))
    d = {}
    ans = []
    for i in range(1, n + 1):
        d[i] = 0
    for i, a in enumerate(A[::-1]):
        i = n - i
        if d[i] % 2 != a:
            ans.append(str(i))
            for divisor in make_divisors(i):
                d[divisor] += 1
    print(len(ans))
    print(' '.join(ans))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
ans = []
for i in reversed(range(n)):
    if A[i]:
        ans.append(i+1)
        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(ans) > 0:
    print(len(ans))
    print(*ans)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
def div(n):
    lower_div, upper_div = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_div.append(i)
            if i != n // i:
                upper_div.append(n // i)
        i += 1
    return lower_div + upper_div[::-1]

def main():
    n = int(input())
    A = list(map(int, input().split()))
    L = [0] * n
    b = []
    cnt = 0
    for i in reversed(range(n)):
        if A[i] != L[i] % 2:
            b.append(i+1)
            cnt += 1
            d = div(i + 1)
            for j in d:
                L[j-1] += 1
    print(cnt)
    print(*b)

main()

Submission status: Time Limit Exceeded

Solution code:
def div(n):
    lower_div, upper_div = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_div.append(i)
            if i != n // i:
                upper_div.append(n // i)
        i += 1
    return lower_div + upper_div[::-1]

n = int(input())
A = list(map(int, input().split()))
L = [0] * n
ans = [0] * n
for i in reversed(range(n)):
    if A[i] != L[i] % 2:
        ans[i] = 1
        d = div(i + 1)
        for j in d:
            L[j-1] += 1
print(n - ans.count(0))
for i in range(n):
    if ans[i]:
        print(i+1, end=' ')

Submission status: Time Limit Exceeded

Solution code:
def divs(n):
    res = []
    i = 1
    while i**2 <= n:
        if n%i == 0: 
            res.append(i)
            if i**2 != n:
                res.append(n//i)
        i+=1 
    return res


def main():
    n = int(input())
    al_0 = list(map(int, input().split()))
    if sum(al_0) == 0:
        print(0)
        return

    al = [0] + al_0
    divs_cnts = [0]*(n+1)
    ans = []
    for i in range(n,0,-1):
        if divs_cnts[i]%2 != al[i]%2:
            ans.append(i)
            div_l = divs(i)
            for d in div_l:
                divs_cnts[d] += 1

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def make_divisors(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

#半分より上は, すべてa通り.
for i in range(1,n+1)[::-1]:
	if c[i-1] % 2 != a[i-1]:
		b.append(i)
		for j in make_divisors(i):
			c[j-1] += 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()))
b = []
c = [[] for _ in range(n)]

def make_divisors(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

#半分より上は, すべてa通り.
for i in range(1,n+1)[::-1]:
	if len(c[i-1]) % 2 != a[i-1]:
		b.append(i)
		for j in make_divisors(i):
			c[j-1].append(0)
print(len(b))
print(" ".join(list(map(str, b))))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
import sys
ans=[]
A=list(map(int,sys.stdin.readline().split()))
def divisor(N):
   S=[]
   for i in range(1,int(N**0.5)+1):
      if N%i==0:
         S.append(i)
         if N//i != i:
            S.append(N//i)
   return S
for i in reversed(range(1,N+1)):
   if A[i-1] == 1:
      ans.append(i)
      tmp=divisor(i)
      for j in tmp:
         A[j-1] = A[j-1] ^ 1
if ans == []:
   print(0)
   exit()
else:
   print(len(ans))
   print(*ans)

Submission status: Time Limit Exceeded

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

last_ans = 0

for i in range(2 ** N):
    hako = [0]*N
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            hako[j] = 1

    #print(hako)
    ans = 0
    for kijun in range(1,N+1):
        baisuu = 1
        total = 0
        while kijun*baisuu <= N:
            if hako[kijun*baisuu-1] == 1:
                total += 1
            baisuu += 1

        total %= 2
        if a[kijun-1] != total:
            ans = 1
            break

    if ans == 0:
        last_ans = 1
        break

if last_ans == 1:
    print(hako.count(1))
    if hako.count(1) != 0:
        buf = [i+1 for i, x in enumerate(hako) if x == 1]
        print(' '.join(map(str, buf)))
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
a = list(map(int, input().split()))
ans = list(np.zeros(N, dtype = int))
ans2 = []
for i in range(N):
    p = N - 1 - i
    if a[p] != sum(ans[p::p + 1]) % 2:
        ans[p] = 1
        ans2.append(str(p + 1))
print(sum(ans))
print(" ".join(ans2))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np 
import sys
input = sys.stdin.readline
N = int(input())
a =[0]+ list(map(int, input().split()))
a_np =np.array(a)
for i in range(N,0,-1):
    a_np[i] =np.sum(a_np[i::i]) %2

print(np.sum(a_np))
a_np =np.delete(a_np,0)
for i,v in enumerate(a_np):
    if v==1:
        print(i+1,end=" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a= list(map(int, input().split()))
s = [0]*n
ans1 = 0
ans2 = ""
for i in range(1, n+1):
  temp = sum(s[n-i::n+1-i])
  if (temp % 2 == 0 and a[-i] == 1) or (temp % 2 == 1 and a[-i] == 0) :
    s[-i] = 1
    ans1 += 1
    ans2 = str(n+1-i) + " " + ans2

print(ans1)
print(ans2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a= list(map(int, input().split()))
s = [0]*n
ans1 = 0
ans2 = ""
for i in range(1, n+1):
  temp = sum(s[n-i::n+1-i])
  #print("i: " + str(i) + "n+1-i: " + str(n+1-i))
  #print(temp)
  if temp % 2 == 0 and a[-i] == 0:
    s[-i] = 0
  elif temp % 2 == 1 and a[-i] == 1:
    s[-i] = 0
  else:
    s[-i] = 1
    ans1 += 1
    ans2 = str(n+1-i) + " " + ans2
  #print(a[-i]) 
  #print(a[n-i::n+1-i])

print(ans1)
print(ans2)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
box = np.zeros(N+1, np.int32)
ans = []
for i in reversed(range(1, N+1)):
    # iの倍数の箱の合計
    if sum(box[i::i]) % 2 != A[i-1]:
        box[i] = 1
        ans.append(i)
    # sum(box[i::i]) % 2 == A[i]
print(len(ans))
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
ak = list(map(int, input().split()))
rng_N = range(1,N+1)
li_ball = [0]*N 
s_ans = ''

for i in range(N-1, math.floor(N/2)-1, -1):
    #print(i)
    li_ball[i] = ak[i]
    if ak[i] == 1:
        li_ball[i] = 1
        s_ans += str(i+1)+'\n'
    
#print(li_ball)

for i in range(math.floor(N/2)-1, 0, -1):
    #print(i)
    
    li = [li_ball[r-1] for r in rng_N if r % (i+1) == 0][1:]
    #print(li)
    if sum(li)%2 != ak[i]:
        li_ball[i] = 1
        s_ans += str(i+1)+'\n'
        
    #print(li_ball)
    
if sum(li_ball)%2 != ak[0]:   
    li_ball[0] = 1
    s_ans += '1'
#print(li_ball)

print(sum(li_ball))
print(s_ans)

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)

    # divisors.sort()
    return divisors


ans = []
c = 0
for i in range(N, 0, -1):
    if A[i-1] % 2 == 1:
        c += 1
        ans.append(i)
        for j in make_divisors(i):
            A[j-1] += 1
print(c)
if c != 0:
    print(*ans[::-1])

Submission status: Time Limit Exceeded

Solution code:
import sys


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


sys.setrecursionlimit(10 ** 9)


MOD = 10 ** 9 + 7


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = []
    C = [0] * N

    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[N - i - 1] == 1:
            if C[N - i - 1] == 0:
                B.append(N - i)
                D = make_divisors(N - i)
                for d in D:
                    C[d - 1] += 1
                    C[d - 1] %= 2
        else:
            if C[N - i - 1] == 1:
                B.append(N - i)
                D = make_divisors(N - i)
                for d in D:
                    C[d - 1] += 1
                    C[d - 1] %= 2
    print(len(B))
    print(*B, sep=" ")


if __name__ == "__main__":
    main()

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):
    for j in range(i,n):
        if not sum(b[i+1:n:i+1]) %2 and a[j]==1:
            b[i] = 1 

print(sum(b))
print(" ".join([str(i)  for i in b if i== 1]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
k = [0 for i in range(n)]
t = []
for i in range(n-1,-1,-1):
  a = l[i]
  if a!=k[i]:
    t.append(i+1)
    for j in range(i,-1,-1):
      if (i+1)%(j+1)==0:
        k[j] += 1
        k[j] %= 2
if len(t)==0:
  print(0)
else:
  print(len(t))
  print(*t)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
def main():
    N = int(readline())
    A = np.zeros(N+1, dtype=np.int64)
    A[1:] = np.array(readline().split(), np.int64)
    table = np.zeros(N+1, dtype=np.int64) 
    for i in reversed(range(1, N+1)):
        table[i] = (table[::i].sum()+A[i])%2

    print(table.sum())
    for i in range(N):
        if table[i+1]:
            print(i+1, end=' ')
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
def main():
    N = int(readline())
    A = np.zeros(N+1, dtype=np.int64)
    A[1:] = np.array(readline().split(), np.int64)
    table = np.zeros(N+1, dtype=np.int64) 
    for i in np.arange(1,N+1, dtype=np.int64)[::-1]:
        table[i] = (table[::i].sum()+A[i])%2

    print(table.sum())
    for i in range(N):
        if table[i+1]:
            print(i+1, end=' ')
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

box=[]
for i in range(n,0,-1):
  t=0
  for j in box:
    if j%i == 0:
      t+=1
  if t%2 != a[i]:
    box.append(i)
else:
  print(len(box))
  box=[str(i) for i in box]
  print(" ".join(box))
#print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def make_divisors(n):
    # exclude itself
    divisors = [1]
    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 = list(map(int, input().split()))
    S = [0] * (N)
    B = []
    for i in range(N - 1, -1, -1):
        S[i] %= 2
        if A[i] != S[i]:
            S[i] += 1
            B.append(i + 1)
            ds = make_divisors(i + 1)
            for d in ds:
                S[d - 1] += 1
        else:
            continue

    print(len(B))
    print(*B, sep=" ")


if __name__ == "__main__":
    main()

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()))
is_ball = [-1]*(N+1)
for i in range(N,-1,-1):
  is_ball[i] = A[i-1]
  divisors = make_divisors(i)
  if A[i-1] == 1:
    for div in divisors:
      A[div-1] ^= 1
      
b=[]

for i in range(1,N+1):
  if is_ball[i] == 1:
    b.append(i)
    
print(len(b))
print(" ".join(map(str,b)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
index = np.arange(1, N+1)
ans = np.array([0] * N)
for i in index[::-1]:
  if sum(ans[index%i==0]) % 2 == A[i-1]:
    continue
  else:
    ans[i-1] += 1
print(sum(ans))
print(' '.join((np.where(ans > 0)[0] +1).astype(str)))

Submission status: Time Limit Exceeded

Solution code:
def factor(N):
    arr=[]
    for i in range(1,int(N**0.5)+1):
        if(N%i==0):
            arr.append(i)
            if(N//i!=i):
                arr.append(N//i)
    return arr
N=int(input())
fac=[factor(i+1) for i in range(N)]
A=list(map(int,input().split()))
ball=[0]*N
res=[]
for i in reversed(range(N)):
    y=0
    if ball[i]!=A[i]:
        y=1
        ball[i]=(ball[i]+1)%2
        res.append(i+1)
        for k in fac[i]:
            ball[k-1]=(ball[k-1]+1)%2
print(len(res))
print(*res,sep=' ')

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)
    return divisors

N = int(input())
a = list(map(int, input().split()))
b = []
multiple = [[i] for i in range(1,N+1)]
balls = [0] * N

for i in range(N,0,-1):
    if balls[i-1] % 2 != a[i-1]:
        for x in make_divisors(i):
            balls[x-1] += 1
        b.append(i)
print(len(b))
print(*b)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter 

N,*a = map(int,open(0).read().split())
for i in range(1<<N):
    bit_str = format(i,'b').zfill(N)
    r_bit_str = list(reversed(bit_str))
    flg = True
    ans = []
    for j in range(N):
        parts_bit = r_bit_str[j::j+1]
        c = Counter(parts_bit)
        sum1 = c["1"]
        if sum1 % 2 != a[j]:
            flg = False
            break
        elif a[j] == 1:
            ans.append(str(j+1))
    if flg:
        print(len(ans))
        print(" ".join(ans))
        sys.exit()
print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter 

N,*a = map(int,open(0).read().split())
for i in range(1<<N):
    bit_str = format(i,'b').zfill(N)
    r_bit_str = list(reversed(bit_str))
    flg = True
    for j in range(N):
        parts_bit = r_bit_str[j::j+1]
        c = Counter(parts_bit)
        sum1 = c["1"]
        if sum1 % 2 != a[j]:
            flg = False
            break
    if flg:
        ans = []
        for i in range(len(r_bit_str)):
            if r_bit_str[i] == "1":
                ans.append(str(i+1))
        print(len(ans))
        print(" ".join(ans))
        sys.exit()
print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys

N,*a = map(int,open(0).read().split())
for i in range(1<<N):
    bit_str = list(reversed(str(i).zfill(N)))
    flg = True
    for j in range(N):
        parts_bit = bit_str[j::j+1]
        _sum = 0
        for k in parts_bit:
            _sum += int(k)
        if _sum % 2 != a[j]:
            flg = False
            continue
    if flg:
        ans = []
        for i in range(len(bit_str)):
            if bit_str[i] == "1":
                ans.append(str(i+1))
        print(len(ans))
        print(" ".join(ans))
        sys.exit()
print(-1)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    A = [0] + A
    b = A[:]
    n = N // 2 + 1
    m = sum(b[n:])
    for i in range(n - 1, 0, -1):
        sum_ = sum([v for j, v in enumerate(b) if not j % i])
        if A[i] != sum_ % 2:
            b[i] = (b[i] + 1) % 2
        m += b[i]

    print(m)
    if m:
        print(*[i for i, v in enumerate(b) if v])


main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
FB = [0 for _ in range(N//2)]
SB = A[N//2:N]
B = FB + SB
S = [i for i in range(1,N//2+1)]
FH = A[0:N//2]
for i in range(1,len(FH)+1):
    s = 0
    for j in range(2,N//S[-i]+1):
        s += B[S[-i]*j-1]
    if s % 2 != FH[-i]:
        FB[-i] = 1
    B = FB + SB
ans = []
for i in range(N):
    if B[i] == 1:
        ans.append(i+1)
print(len(ans))
print(*ans)

Submission status: Time Limit Exceeded

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

#  nの約数をO(root(n))で全列挙、
# sortするなら O(root(n) * root(n)log(root(n))) --> O(n * log(n))
def make_divisors(n):
    import math
    divisors = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0: #割り切れるとき
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

B = [0] * (N + 1)
ans = [0] * (N + 1)
for i in range(N, 0, -1):
    if B[i] == A[i]:
        continue
    ans[i] = 1
    lst = make_divisors(i)
    for tmp in lst:
        B[tmp] += 1
        B[tmp] %= 2

M = sum(ans)
print (M)
for index, b in enumerate(ans):
    if b == 1:
        print (index, end = ' ')

Submission status: Time Limit Exceeded

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

    for i in range(N//2, 0, -1):
        sum_m = sum([A[j] for j in range(i*2, N+1) if j%i==0])
        if A[i] == 0:
            if sum_m % 2 == 1:
                A[i] = 1
        else:
            if sum_m % 2 == 1:
                A[i] = 0

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

res = np.zeros_like(As)
for idx, ai in zip(np.arange(N-1, -1, -1), As[::-1]):
    oe = res[idx::(idx+1)].sum() % 2
    res[idx] = ai ^ oe

idxs = np.where(res)[0] + 1
print(len(idxs))
print(" ".join(idxs.astype(str)))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for n in range(N,0,-1):
    if A[n-1]==1:
        B[n-1]=1
        for x in range(1,int(n**0.5)+1):
            if n%x==0:
                if x**2==n:
                    A[x-1]=(A[x-1]+1)%2
                else:
                    y=n//x
                    A[x-1]=(A[x-1]+1)%2
                    A[y-1]=(A[y-1]+1)%2
print(sum(B))
for i in range(N):
    if B[i]==1:
        print(i+1,end=" ")