Problem:


Score : 400 points

Problem Statement

There are N empty boxes arranged in a row from left to right.
The integer i is written on the i-th box from the left (1 \leq i \leq N).

For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.

We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:

For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.

Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

a_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If a good set of choices does not exist, print -1.

If a good set of choices exists, print one such set of choices in the following format:

M
b_1 b_2 ... b_M

where M denotes the number of boxes that will contain a ball, and b_1,\ b_2,\ ...,\ b_M are the integers written on these boxes, in any order.

Sample Input 1

3
1 0 0

Sample Output 1

1
1

Consider putting a ball only in the box with 1 written on it.

There are three boxes with multiples of 1 written on them: the boxes with 1, 2, and 3. The total number of balls contained in these boxes is 1.

There is only one box with a multiple of 2 written on it: the box with 2. The total number of balls contained in these boxes is 0.

There is only one box with a multiple of 3 written on it: the box with 3. The total number of balls contained in these boxes is 0.

Thus, the condition is satisfied, so this set of choices is good.

Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Putting nothing in the boxes can be a good set of choices.



Sample input:
3
1 0 0


Sample output:
1
1

Submission status: Accepted

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

# ex. 3の倍数は 3*1, 3*2, ..., 3*(N//3 - 1), 3*(N//3)

# 箱Nから確定させていく (箱番号が大きいものほど、考慮すべき箱の数が少ない)

# 箱iについて
for i in range(N, 0, -1):
    cnt = 0
    # 2*i, 3*i, ..., N//i * i について、現在のボールの総和
    for j in range(N // i, 1, -1):
        cnt += box[i * j]
    # 既に偶奇が満たされている場合
    if cnt % 2 == a[i]:
        box[i] = 0
    # 偶奇が満たされていない場合
    else:
        box[i] = 1
        ans.append(i)

ans = ans[::-1]
print(len(ans))
if len(ans) > 0:
    print(*ans)

Submission status: Accepted

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

def fast_factorization_init(N):
    res=list(range(N))
    for i in range(2,N):
        if i*i>N:
            break
        for j in range(i*i,N,i):
            if res[j]==j:
                res[j]=i
        if res[i]<i:
            continue
    return res            
    
min_factors=fast_factorization_init(2*10**5+10)
def fast_factorization(n):
    res=[]
    while n>1:
        res.append(min_factors[n])
        n//=min_factors[n]
    return res

def factors(n):
    res=[1]
    for i,j in Counter(fast_factorization(n)).items():
        res+=[r*i**(b+1) for r in res for b in range(j)]
    return res

res=[0]*(N+1)
num=0
for n in reversed(range(N)):
    res[n+1]=A[n+1]
    if A[n+1]:
        num+=1
        for m in factors(n+1):
            A[m]=(A[m]+1)%2
print(num)
print(*[i+1 for i in range(N) if res[i+1]>0],sep='\n')

Submission status: Accepted

Solution code:

url = "https://atcoder.jp//contests/abc134/tasks/abc134_d"

def main():
    n = int(input())
    a = [0]
    a.extend(list(map(int, input().split())))
    balls = [0]*(n+1)
    b = {}
    for i in range(n, 0, -1):
        ball = 0
        for j in range(i, n+1, i):
            ball += balls[j]
        if ball % 2 != a[i]:
            b[i] = 1
            balls[i] = 1
    if len(b) == 0:
        print(0)
        exit()
    else:
        print(len(b))
    ks = sorted(b.items(), key=lambda x:x[0])
    for k in ks:
        print(k[0], end=" ")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():    
    n = int(input())
    a = list(map(int,input().split()))
    b = [0]*n
    ans = []    
    for i in range(n-1, -1, -1):
        if sum(b[i::i+1])%2 != a[i]:
            b[i] = 1
            ans.append(i+1)
    print(len(ans))
    if len(ans):
        print(*ans)
        
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

for i, a in list(enumerate(A))[::-1]:
    i += 1
    d = sum(B[i - 1::i])
    if a != (d % 2):
        B[i - 1] = 1
print(sum(B))
for i, b in enumerate(B):
    if b != 0:
        print(i+1)

Submission status: Accepted

Solution code:
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n = read_int()
    a = read_int_list()
    b = [0] * n
    ans = []
    for i in range(n - 1, -1, -1):
        if sum(b[i::i + 1]) % 2 != a[i]:
            b[i] = 1
            ans.append(i + 1)
    print(len(ans))
    if len(ans): print(*ans)    
    
if __name__ == '__main__':
    Main()

Submission status: Accepted

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

cnt=[0]*n
lst=[]

for i in range(n,0,-1):
    if cnt[i-1]%2==a[i-1]:
        continue
    
    else:
        lst.append(str(i))
        xxx=make_divisors(i)

        for j in xxx:
            cnt[j-1]+=1


print(len(lst))

if len(lst)>0:
    print(' '.join(lst))

Submission status: Accepted

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

ans = [0 for i in range(N)]
for i in range(N-1,-1,-1):
    val = i+1
    if val*2>N:
        if A[i]==0:
            ans[i] = 0
        else:
            ans[i] = 1
    else:
        tmp = 0
        res = val
        while(1):
            if val>N:
                break
            tmp += ans[val-1]
            val += res

        if A[i]==0:
            if tmp%2==0:
                ans[i]=0
            else:
                ans[i]=1
        else:
            if tmp%2==0:
                ans[i]=1
            else:
                ans[i]=0
#print(*ans)
cnt = 0
b=[]
for i in range(N):
    if ans[i]==0:
        continue
    cnt += 1
    b.append(i+1)

print(cnt)
print(*b)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]+[int(x) for x in input().split()]
boal=[0]*(n+1)
m=0
ans=[]
for i in range(n,0,-1):
    k=1
    sum_boal=0
    while i*k<n+1:
        sum_boal+=boal[i*k]
        k+=1
    if sum_boal%2!=a[i]:
        boal[i]+=1
        m+=1
        ans.append(i)
print(m)
print(*ans)

Submission status: Accepted

Solution code:
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque
# import sympy

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

A.insert(0, 0)
B = [0] * (N + 1)

for i in range(N, 0, -1):
    j = 1
    cnt = 0
    while(i * j <= N):
        cnt += B[i * j]
        j += 1
    flg = cnt % 2
    if A[i] != flg:
        B[i] = 1

# print(B)
print(sum(B))
for i, b in enumerate(B):
    if b == 1:
        print(i)

Submission status: Accepted

Solution code:
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0] * n
    for i in range(n, 0, -1):
        s = 0
        for j in range(i, n + 1, i):
            s += ans[j - 1]
        if s % 2 == a[i - 1]:
            ans[i - 1] = 0
        else:
            ans[i - 1] = 1
    m = sum(ans)
    print(m)
    for i in range(1, n + 1):
        if ans[i - 1]:
            print(i)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(N, 0, -1):
	tmpBalls = 0
	x = 1
	while i * x <= N:
		tmpBalls += balls[i*x]
		x += 1
	
	if A[i] == 1 and tmpBalls % 2 == 1:
		pass
		
	elif A[i] == 1 and tmpBalls % 2 == 0:
		balls[i] += 1
	
	elif A[i] == 0 and tmpBalls % 2 == 1:
		balls[i] += 1
	
	elif A[i] == 0 and tmpBalls % 2 == 0:
		pass
		

isOkay = True
for i in range(1, N+1):
	if balls[i] > 1:
		print(-1)
		exit()
	
print(balls.count(1))	
for i in range(1, N+1):
	if balls[i]:
		print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=[0]*N
for i in range(N):
  n=N-i
  add=A[n-1]
  n_tmp=n
  while True:
    n_tmp+=n
    if n_tmp>N:break
    if ans[n_tmp-1]:
      add=0 if add else 1
  if add:
    ans[n-1]=1
print(ans.count(1))
ans2=[]
for i,v in enumerate(ans):
  if v:
    ans2.append(i+1)
print(*ans2)

Submission status: Accepted

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

for n in range(N,0,-1):
  B[n] = (sum(B[n::n])+A[n-1])%2

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

Submission status: Accepted

Solution code:
N = int(input())
a = [0]+list(map(int,input().split()))
ls = [0]*(N+1)
for i in range(N, 0, -1):
    sm = 0
    for j in range(i, N+1, i):
        sm += ls[j]
    ls[i] = (sm % 2) ^ a[i]
b = [i for i in range(N+1) if ls[i] == 1]
print(len(b))
print(*b)

Submission status: Accepted

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

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

print(sum(B))
print(*[i + 1 for i, b in enumerate(B) if b == 1])

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C



N,A=ilint()
a=[0]+A[:]
x=[0]*(N+1)
ans=[]
for k in range(N,0,-1):
    tmp=0
    l=2*k
    while l<=N:
        tmp+=x[l]
        l+=k
    if tmp%2!=a[k]:
        x[k]=1
        ans.append(k)
print(len(ans))
if len(ans)>0:
    lprint(ans,' ')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

b = [0] * n
c = []
for i in range(n-1, -1, -1):
    v = i + 1
    s = 0
    for j in range(1, 10**6):
        if v*j > n:
            break    
        s += b[v*j-1]
    if s % 2 != a[i]:
        b[i] = 1
        c.append(v)
print(len(c))
for i in reversed(c):
    print(i)

Submission status: Accepted

Solution code:
from collections import deque
N=int(input())
A=list(map(int,input().split()))
reverse_A=list(reversed(A))
numbers=[]
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]
boxes=[0 for _ in range(N)]
for n in range(N):
    yakusuu=make_divisors(n+1)
    numbers+=[yakusuu]
reverse_numbers=list(reversed(numbers))
answers=[0 for _ in range(N)]
balls=[0 for _ in range(N)]
for n in range(N-1):
    number=reverse_numbers[n]
    if balls[n]%2==0 and reverse_A[n]==1:
        answers[n]+=1
        for num in number:
            balls[-num]+=1
    elif balls[n]%2==1 and reverse_A[n]==0:
        answers[n] += 1
        for num in number:
            balls[-num] += 1
if sum(answers)%2==0 and reverse_A[-1]==1:
    answers[-1]+=1
elif sum(answers)%2==1 and reverse_A[-1]==0:
    answers[-1]+=1
print(sum(answers))
reverse_answers = list(reversed(answers))
kotae = []
for n in range(N):
    if reverse_answers[n] != 0:
        kotae.append(n + 1)
print(*kotae)

Submission status: Accepted

Solution code:
import math

def main():
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	B = [0] * N
	if N == 1:
		if A[0] == 1:
			print(1)
			print(1)
		else:
			print(0)
		return 0
	for i in range(1, N):
		for j in range(math.ceil(N / (i + 1)), math.floor(N / i) + 1):
			ball = 0
			for k in range(2 * j, N + 1, j):
				ball += B[k - 1]
			B[j - 1] = (ball % 2 + A[j - 1]) % 2
	ans = [str(x + 1) for x, v in enumerate(B) if v == 1]
	print(len(ans))
	if len(ans) > 0:
		print(" ".join(ans))

main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left, bisect_right
from functools import lru_cache
MOD = int(1e9)+7
INF = float('inf')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    xd = [0] * n
    ans = []
    for i in range(n-1,-1,-1):
        cnt = 0
        for j in range(i, n, i + 1):
            cnt += xd[j]
        cnt %= 2
        if cnt != a[i]:
            ans.append(i + 1)
            xd[i] = 1
    ans.reverse()
    print(len(ans))
    if ans:
        print(*ans)
        

    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""


"""

Submission status: Accepted

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

b = [0] * (N + 1)

for i in range(N, 0, -1):
    if sum(b[::i]) % 2 != a[i-1]:
        b[i] = 1

s = sum(b)
print(sum(b))
if s != 0:
    for i in range(N+1):
        if b[i] == 1:
            print(i, end=" ")

Submission status: Accepted

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

input_num = [0 for _ in range(n)]

for i in range(n-1, -1, -1):
    tmp = 0
    j = i+i+1
    while j < n:
        tmp += input_num[j]
        j += i+1

    if tmp % 2 != a[i]:
        input_num[i] = 1

print(sum((input_num)))
for i, j in enumerate(input_num):
    if j:
        print(i+1, end=' ')

Submission status: Accepted

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

Submission status: Accepted

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

r=""
c=0
for i in range(1,n+1):
  if ans[i]:
    c+=1
    r+=str(i)+" "
print(c)
print(r[:-1])

Submission status: Accepted

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

for i in range(N,0,-1):
    res = 0
    for j in range(1,N+1):
        if i*j>N:
            break
        else:
            res += ans[i*j]
      
    if res%2 != a[i-1]:
        ans[i] += 1
        
print(sum(ans))
A = []
for i,v in enumerate(ans):
    if v>0:
        A.append(i)
        
        
print(*A)

Submission status: Accepted

Solution code:
n = int(input())
A = [0] + list(map(int,input().split()))
B = [0]*(n+1)
m = 0
for i in range(n,0,-1):
    cnt = 0
    for j in range(i,n+1,i):
        cnt += B[j]
    if cnt%2==A[i]:
        continue
    else:
        B[i] =1
        m += 1
print(m)
for i in range(len(B)):
    if B[i]==1:
        print(i)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = [0] + list(map(int, input().split( )))
B = [0]*(N+1)
s = 0
for i in reversed(range(1, N+1)):
  ball = 0  
  for j in range(i,N+1,i):
    ball += B[j]
  if ball%2 != A[i]:
    B[i] = 1
    s += 1

print(s)
print(*[i for i, b in enumerate(B) if b == 1], sep=' ')

Submission status: Accepted

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

hako = [0]*n

for i in range(n,0,-1):
    tmp = i
    su = 0
    while tmp<=n:
        su += hako[tmp-1]
        tmp += i
    if su % 2 == a[i-1]:
        continue
    else:
        hako[i-1] = 1

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

Submission status: Accepted

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

ans = [False] * n

for i in range(n//2, n):
    ans[i] = a[i]

for i in range(n//2-1, -1, -1):
    mod = False
    for j in range(i, n, i+1):
        if ans[j] == 1:
            mod = not mod

    mod = 1 if mod else 0

    ans[i] = True if mod != a[i] else False

cnt = 0
ind = []
for i in range(n):
    if ans[i] == True:
        cnt += 1
        ind.append(i+1)

print(cnt)
if cnt > 0:
    print(" ".join(map(str, ind)))

Submission status: Accepted

Solution code:
N = int(input())
Alist = list(map(int,input().split()))
Answer = [0]*(N+1)
M = 0
for i in range(1,len(Alist)+1):
    A = Alist[-i]
    n = (N+1)-i
    if sum(Answer[n::n])%2 != A:
        Answer[-i] = 1
        M += 1
print(M)
Ans = []
for k in range(len(Answer)):
    if Answer[k] == 1:
        Ans.append(k)
print(*Ans[0:],end="\t")

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.buffer.readline
N = int(input())
A = np.array(list(map(int, input().split())))

B = np.array([0] * N)
for i in range(len(A), 0, -1):
    v = B[2 * i - 1::i].sum() % 2
    if A[i - 1] != v:
        B[i - 1] = 1
# print(f'{B=}')

M = B.sum()
print(M)
idx = np.where(B == 1)[0] + 1
print(*idx, sep=' ')

Submission status: Accepted

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

    ans = set()
    
    for i in range(n, 0, -1):
        now = 0
        for j in range(2*i, n+1, i):
            if j in ans:
                now += 1
        if now % 2 != a[i-1]:
            ans.add(i)
    
    return ans

if __name__ == '__main__':
    x = solve()
    print(len(x))
    print(*x, sep=' ')

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    box = set()

    for i in range(N):
        num = N -i
        sum_num  = 0
        for j in range(1, N//num +1):
            if j*num in box:
                sum_num += 1

        if As[num-1] != sum_num % 2:
            box.add(num)

    print(len(box))

    for item in box:
        print(item)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

b = [0]*(n+1)

for i in reversed(range(1,n+1)):
    ball = 0
    base = i+1

    for j in range(i,n+1,i):
        ball += b[j]
    
    if ball % 2 != lis[i]:
        b[i] = 1

print(sum(b))
print(*[i for i ,b in enumerate(b) if b == 1], sep=' ')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
box = set([])
for i in range(n,0,-1):
  cnt = 0
  for j in range(1,n//i+1):
    if i*j in box:
      cnt += 1
  if cnt%2 != a[i-1]:
    box.add(i)
print(len(box))
print(*box)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
box = set([])
for i in range(n,0,-1):
  cnt = 0
  for j in range(1,n//i+1):
    if i*j in box:
      cnt += 1
  if cnt%2 != a[i-1]:
    box.add(i)
print(len(box))
print(*box)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=[0] + list(map(int,input().split()))
B=[0]*(N+1)#ボールの管理

#大きい数字から1まで順に見ていく
for i in reversed(range(1,N+1)):
  ball=0
  base=i+1

  #iからNまでiずつ見てボールを足す(j=iの倍数)
  for j in range(i,N+1,i):
    ball+=B[j]

  #もし足したボールの数%2がA[i]と合わないなら合わせる
  if ball%2 != A[i]:
    B[i] = 1

print(sum(B))#ボールの入った箱の総数
#もしBに1が入っている場所があればその場所を出力
print(*[i for i,b in enumerate(B) if b==1],sep=' ')

Submission status: Accepted

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

ans=[0 for _ in range(n+1)]
t=[]
S=0

for i in range(n):
  b=n-i
  c=(n-i)*2
  ch=0
  while c<=n:
    ch+=ans[c]
    c+=b
    
  if ch%2==0:
    if a[b-1]==1:
      ans[b]+=1
      S+=1
      t.append(str(b))
  else:
    if a[b-1]==0:
      ans[b]+=1
      S+=1
      t.append(str(b))
      

print(S)
if S>0:
  
  print(' '.join(t))

Submission status: Accepted

Solution code:
n = int(input())
alst = list(map(int, input().split()))
divisor_lst = [[0] for _ in range(n)]
ans = []
for i in range(2, n + 1):
    for k in range(i * 2, n + 1, i):
        divisor_lst[k - 1].append(i - 1)
for i in range(n - 1, -1, -1):
    if alst[i] == 1:
        for j in divisor_lst[i]:
            alst[j] += 1
            alst[j] %= 2
        ans.append(i + 1)
print(len(ans))
print(*ans)

Submission status: Accepted

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

for i in range(N,0,-1):
  if sum(res[j] for j in range(i,N+1,i)) % 2 != A[i]:
    res[i] = 1
    M += 1
    
print(M)
print(*[k for k, r in enumerate(res) if r])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]

X = [0 for _ in range(N)]
ans = []
for i in range(N)[::-1]:
    v = 0
    for j in range(i, N, i+1):
        v += X[j]
    if v % 2 != A[i]:
        X[i] = 1
        ans.append(i+1)

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

Submission status: Accepted

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

for i in range(n, 0, -1):
    if i > 0 - -n//2:
        l[i] = a[i]
    else:
        if a[i] != sum(l[i::i])%2:
            l[i] = 1

print(l.count(1))

for i in range(1, n + 1):
    if l[i] == 1:
        print(i)

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    a=LI()
    b=[0]*N
    
    
    for i in range(N-1,-1,-1):
        temp=0
        for j in range(i+1,N+1,i+1):
            jj=j-1
            if b[jj]:
                temp+=1
        temp=temp%2
        if temp!=a[i]:
            b[i]=1
            
    M=sum(b)
    ans=[]
    for i in range(N):
        if b[i]:
            ans.append(i+1)
            
    print(M)
    print(' '.join(map(str, ans)))
        

main()

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())
a = [0] + list(map(int, input().split()))

b = [0 for i in range(N+1)]
c = []
for i in range(N,0,-1):
    ii = 2*i
    s = 0
    while ii <= N:
        s += b[ii]
        ii += i
    s = s % 2
    if s == a[i]:
        b[i] = 0
    else:
        b[i] = 1
        c.append(i)

print(len(c))
if len(c) > 0:
    c = map(str, c)
    print(" ".join(c))

Submission status: Accepted

Solution code:
n=int(input())

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

l=[-1 for _ in range(n)]
for i in reversed(range(1,n+1)):
    si=0
    j=2*i-1
    while j<=n-1:
        si+=l[j]
        j+=i
    si=si%2
    if si==0:
        l[i-1]=a[i-1]
    elif a[i-1]==0:
        l[i-1]=1
    else:
        l[i-1]=0

b=[]
for i in range(n):
    if l[i]==1:
        b.append(i+1)

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

Submission status: Accepted

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

m = 0
b = [0] * (n + 1)

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

print(m)
if m > 0:
    print(*[i for i, j in enumerate(b) if j == 1], sep=' ')

Submission status: Accepted

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

ball = [0 for i in range(n)]

for i in reversed(range(n)):
  if n//2 < i:
    ball[i] = a[i]
  else:
    if (sum(ball[i::(i+1)]) - a[i]) % 2 == 0:
      ball[i] = 0
    else:
      ball[i] = 1


num = [str(i+1) for i, x in enumerate(ball) if x == 1]

if len(num) == 0:
  print('0')
else:
  print(len(num))
  num = ' '.join(num)
  print(num)

Submission status: Accepted

Solution code:
N=int(input())
*A,=map(int,input().split())
D=[[1]for _ in range(N+1)]
for i in range(2,N+1):
    j=1
    while i*j<=N:
        D[i*j].append(i)
        j+=1

D=D[1:]
B=[0]*N
ans=[]
i=1
while i<=N:
    B[-i]%=2
    if B[-i]==A[-i]:
        i+=1
        continue
    else:
        ans.append(N-i+1)
        for d in D[-i]:
            B[d-1]+=1
        B[-i]%=2
    i+=1
        
M=len(ans)
ans.sort()
print(M)
print(*ans)

Submission status: Accepted

Solution code:
def cin():  return list(map(int,input().split()))

N = cin()[0]
a = cin()

rec = [0 for _ in range(N + 10)]

for i in reversed(range(1, N + 1)):
    cnt = 0
    tmp = i
    while(tmp <= N):
        cnt += rec[tmp]
        tmp += i
    if cnt % 2 == a[i - 1]:  continue
    else:  rec[i] = 1
        
l = []
for i in range(1, N + 1):
    if rec[i]:  l.append(i)
print(len(l))
print(*l)

Submission status: Accepted

Solution code:
N = int(input())
A = [0] + list(map(int, input().split()))
Ans = [0] * (N+1)
for i, a in zip(range(N, 0, -1), A[:0:-1]):
    n = 0
    for aj in Ans[i*2::i]:
        n ^= aj
    Ans[i] = n ^ a
Ans = [i for i, a in enumerate(Ans[1:], 1) if a]
print(len(Ans))
print(" ".join(map(str, Ans)))

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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]
n=int(input())
a=[0]
a.extend(lmp())
l=[0]*(n+1)#iの倍数の箱にいくつ玉が入っているか
ans=[]

for i in range(n,0,-1):
    if (l[i]-a[i])%2==1:
        ans.append(i)
        for k in make_divisors(i):
            l[k]+=1

print(len(ans))
print(*ans[::-1])