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: Wrong Answer

Solution code:
from math import ceil

n = int(input())

a = [0] + [int(x) for x in input().split()]

c = [0 for i in a]

for i in range(n, int(n/2), -1):
    c[i] = a[i]

for i in range(int(n/2), 0, -1):
    cr = 0
    for j in range(i, n+1, i):
        cr = cr + c[i]
    cr = cr % 2
    cr = cr ^ a[i]
    c[i] = cr

x = c.count(1)

print(x)

for i in range(len(c)):
    if c[i] == 1:
        print(i, end=' ')

Submission status: Wrong Answer

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

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

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

for i,a in enumerate(A,1):
    if score[i] & 1 != a:
        answer.append(i)
        score[i::i] += 1

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

Submission status: Wrong Answer

Solution code:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
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 = [0]+[int(i) for i in input().split()]
T = [0]*(N+1)
FLAG = []
for i in range(N,0,-1):
	if (T[i]+A[i])%2:
		FLAG.append(str(i))
		for j in make_divisors(N):
			T[j] += 1
size = len(FLAG)
print(size)
if size:
	print(" ".join(FLAG))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
a = LI()

b = [0 for i in range(N)]
cnt = 0
for i in reversed(range(N)):
    part_sum = 0
    # print("i:",i)
    for skip in range(N//(i+1)-1):
        # print(skip)
        part_sum += b[skip * (i+1)-1]
    if part_sum % 2 == 0:
        b[i] = a[i]
    elif a[i] == 0:
        b[i] = 1
    else:
        b[i] = 0
poss = []
for i in range(N):
    if b[i] == 1:
        cnt += 1
        poss.append(i+1)

print(cnt)
for pos in poss:
    print(pos)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

B = [0] * (N + 1)

for i in reversed(range(1, N + 1)):
    tmp = 0
    for j in range(i, N + 1, i):
        tmp += B[j]

    if tmp % 2 != A[i]:
        B[i] = 1

for i in range(1, N + 1):
    tmp = 0
    for j in range(i, N + 1, i):
        tmp += B[j]
    if A[i] != tmp:
        print(i)
        print(-1)
        exit()

print(sum(B))
print(*B[1:], sep=' ')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
li = []
for ind,i in enumerate(a):
    if(i==1):
        li.append(ind+1)
print(len(li))
if(len(li)==0):
    print(0)
else:
    print(*li)

Submission status: Wrong Answer

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

    # divisors.sort()
    return divisors

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

Submission status: Wrong Answer

Solution code:
def main():
    n = input()
    aa = map(int, raw_input().split())
    ans = [0] * n
    m = 0
    for i in xrange((n + 1) // 2, n):
        if aa[i] == 1:
            ans[i] = 1
            m += 1
    for i in xrange((n + 1) // 2 - 1, -1, -1):
        s = sum(ans[i::i + 1]) % 2
        if aa[i] != s:
            ans[i] = 1
            m += 1
    print m
    for i, a in enumerate(aa, 1):
        if a:
            print i


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
aa = inpl()


n = N
ans = [0]*(N+1)
cnts = [0]*(N+1)

for a in reversed(aa):
    if cnts[n]%2 == a:
        ans[n] = 0
    else:
        ans[n] = 1
        r = 1
        while r <= math.sqrt(n):
            if n%r == 0:
                cnts[r] += 1
            r += 1
    n -= 1

tmp = sum(ans)
if tmp == 0:
    print(0)
else:
    print(tmp)
    fans = []
    for i,x in enumerate(ans):
        if x == 1:
            fans.append(str(i))
    print(' '.join(fans))

Submission status: Wrong Answer

Solution code:
def div(val):
  ret=[]
  for i in range(1,int(val**0.5)+1):
    if val%i==0:
      ret.append(i)
      if val//i!=i:
        ret.append(val//i)
  return ret

n=int(input())
arr=list(map(int,input().split()))
cnt=[0]*n
num=0
ans=[0]*n
for i in range(n-1,-1,-1):
  if (arr[i]+cnt[i])%2==0:
    ans[i]=0
  else:
    ans[i]=1
    num+=1
  for j in div(i+1):
    cnt[j-1]+=1
if num==0:
  print(0)
else:
  print(num)
  print(*ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().strip().split(' ')))
A=[0]+A
dp=[0]*len(A)
dp[N]=A[N]
for i in range(N-1,0,-1):
    temp=0
    for j in range(2,len(A)):
        if i*j>=len(A):
            break
        temp+=dp[j*i]
    #temp+dp[i] = A[i] mod 2
    dp[i]=(A[i]-temp)%2
ans=sum(dp[1:])
print(ans)
print(*[1]*ans)

#print(dp[1:])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = []
for i in range(1, N+1):
    temp = 0
    for j in range(1, N//i+1):
        temp += a[j*(i)-1]
    if temp % 2 == 1:
        b.append(i)

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

Submission status: Wrong Answer

Solution code:
# from sys import exit, stderr
# from inspect import currentframe
# def debug(*args):
#     names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
#     print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=stderr)
#     return

N = int(input())
a = [int(n) for n in input().split()]
n = 0
ans = []
for i in range(N):
    if a[i] == 0:
        continue
    else:
        n += 1
        ans.append(i+1)

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

if len(ans) >0:
    print()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print(3*n**2)
    return

#B
def B():
    n,d = LI()
    f = [1]*(n+2*d+2)
    ans = 0
    for i in range(n):
        if f[i]:
            for j in range(i,i+2*d+1):
                f[j] = 0
            ans += 1
    print(ans)
    return

#C
def C():
    n = I()
    a = IR(n)
    mi = max(a)
    if a.count(mi) > 1:
        for i in range(n):
            print(mi)
    else:
        b = [a[i] for i in range(n)]
        b.sort()
        b = b[::-1]
        for i in range(n):
            if mi != a[i]:
                print(mi)
            else:
                print(b[1])

    return

#D
def D():
    n = I()
    a = LI()
    b = []
    for i in range(1,n+1)[::-1]:
        j = 2*i
        k = 0
        while j < n:
            k ^= a[j-1]
            j += i
        if a[i-1]^k:
            b.append(i)
    b = b[::-1]
    print(len(b))
    if b:
        print(*b)
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

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

ans = [0]*N
for i in reversed(range(1,N+1)):
    v = A[i-1]
    for j in range(i,N,i):
        v += ans[j-1]
    ans[i-1] = v % 2

M = sum(ans)
print(M)
if M:
    print(*(i+1 for i,b in enumerate(ans) if b == 1))

Submission status: Wrong Answer

Solution code:
import sys

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


def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    B = [0] * N
    ans = []
    M = 0

    for i in reversed(range(N)):
        if B[i] != A[i]:
            d = divisor(i+1)
            for element in d:
                B[element - 1] = (B[element - 1] + 1) % 2
            M += 1
            ans.append(i+1)

    print(M)
    print(" ".join(map(str, ans)))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
# ABC134-D

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  m=I()
  l=LI()

  print(0)

main()
# print(main())

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print(3*n**2)
    return

#B
def B():
    n,d = LI()
    f = [1]*(n+2*d+2)
    ans = 0
    for i in range(n):
        if f[i]:
            for j in range(i,i+2*d+1):
                f[j] = 0
            ans += 1
    print(ans)
    return

#C
def C():
    n = I()
    a = IR(n)
    mi = max(a)
    if a.count(mi) > 1:
        for i in range(n):
            print(mi)
    else:
        b = [a[i] for i in range(n)]
        b.sort()
        b = b[::-1]
        for i in range(n):
            if mi != a[i]:
                print(mi)
            else:
                print(b[1])

    return

#D
def D():
    n = I()
    a = LI()
    b = []
    for i in range(1,n+1)[::-1]:
        j = 2*i
        while j < n:
            if b:
                if a[i-1] == a[j-1]:
                    print(-1)
                    return
            j += i
        if a[i-1]:
            b.append(i)
    b = b[::-1]
    print(len(b))
    if b:
        print(*b)
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

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

ANS = [0] * N
for i in range(N)[::-1]:
    ans = 0
    for j in range(i+1, N+1, i+1):
        ans ^= A[j-1]
    ANS[i] = ans

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

Submission status: Wrong Answer

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

M = a.count(1)
print(M)
print(' '.join(['1' for _ in range(M)]))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print(3*n**2)
    return

#B
def B():
    n,d = LI()
    f = [1]*(n+2*d+2)
    ans = 0
    for i in range(n):
        if f[i]:
            for j in range(i,i+2*d+1):
                f[j] = 0
            ans += 1
    print(ans)
    return

#C
def C():
    n = I()
    a = IR(n)
    mi = max(a)
    if a.count(mi) > 1:
        for i in range(n):
            print(mi)
    else:
        b = [a[i] for i in range(n)]
        b.sort()
        b = b[::-1]
        for i in range(n):
            if mi != a[i]:
                print(mi)
            else:
                print(b[1])

    return

#D
def D():
    n = I()
    a = LI()
    b = []
    for i in range(1,n+1)[::-1]:
        j = 2*i
        while j < n:
            if a[i-1] == a[j-1] == 1:
                print(-1)
                return
            j += i
        if a[i-1]:
            b.append(i)
    b = b[::-1]
    print(len(b))
    if b:
        print(*b)
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
# from sys import exit, stderr
# from inspect import currentframe
# def debug(*args):
#     names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
#     print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=stderr)
#     return

N = int(input())
a = [int(n) for n in input().split()]
n = 0
ans = []
for i in range(N):
    if a[i] == 0:
        continue
    elif N > 0:
        N -= 1
        n += 1
        ans.append(i+1)
    else:
        break
print(n)
for i in range(len(ans)):
    print(ans[i], end="")

if len(ans) >0:
    print()

Submission status: Wrong Answer

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

if sum(A) > N:
    print(-1)
else:
    A.sort(reverse=True)
    p = A.count(1)
    print(p)
    if p != 0:
        [print(A[i]) for i in range(p)]

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n = int(input())
    a = list(map(int, input().split()))
    res = []
    for i in range(n):
        if a[i] == 1:
            res.append(i + 1)
    print(len(res))
    print(*res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[-1]+[int(i) for i in input().split()]
b=[0 for i in range(N+1)]
for i in range(1,N+1)[::-1]:
    tmp=0
    for j in range(2*i,N+1,i):
        tmp+=b[j]
    if tmp!=a[i]:
        b[i]=1
ans=[]
for i in range(N+1):
    if b[i]==1:
        ans.append(str(i))
print(len(ans))
print(" ".join(ans))

Submission status: Time Limit Exceeded

Solution code:
def divisors(n):
   d=[]
   for i in range(1,int(n**0.5)+1):
       if n%i==0:
           d.append(i)
           if i!=n//i:
               d.append(n//i)
   d.sort()
   return d
n=int(input())
table=[0]*(n+1)
ball=[]
a=list(map(int,input().split()))[::-1]
for i in range(n):
    if table[n-i]!=a[i]:
        ball.append(n-i)
        for j in divisors(n-i):
            table[j]=1-table[j]
print(len(ball))
if len(ball)!=0:
    print(*ball)

Submission status: Time Limit Exceeded

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

m=0
ans=[]
c=[0]*(n+1)
for i in reversed(range(1,n+1)):
  if a[i]%2!=c[i]%2:
    m+=1
    ans.append(i)
    j=1
    r=set()
    while j*j<=i:
      if i%j==0:
        r.add(j)
        r.add(i//j)
      j+=1
    for j in r:
      c[j]+=1
      c[j]%=2
        
print(m)
print(*sorted(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split(' ')]
b=[0 for i in range(n)]
ans=[]
for i in range(len(a),0,-1):
    if a[i-1]!=b[i-1]:
        ans.append(i)
        for j in range(1,i+1):
            if i%j==0:
                b[j-1]=not b[j-1]

print(len(ans))
ans.reverse()
for i in ans:
    print(i,end=' ')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split()))
box=[0]*(n+1)
l=[]
cnt=0
for i in reversed(range(n)):
  i+=1
  r=[ j for j in range(i+1,n+1) if j % i == 0 ]
  for j in r:
    if box[j]==1:
      cnt+=1
  if a[i-1]%2!=cnt%2:
    box[i]=1
    l.append(i)
    
print(len(l))
for s in l:
  print(s, end =" ")

Submission status: Time Limit Exceeded

Solution code:
# 1からNまでの数字それぞれの約数を求める
# Nから(大きい値から)見ていき、1であれば入れる
# 数字iを入れた場合、iの約数の数を+1
# それぞれの数はdictで保持する

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

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

ans_num = 0
ans_list = ""
for i in range(N):
    tmp = N - i
    s = 0
    for j in range(tmp, N+1, tmp):
        s += ans[j-1]

    if s % 2 != A[tmp - 1]:
        ans[tmp - 1] = 1
        ans_num += 1
        ans_list += str(tmp)
        ans_list += " "


print(ans_num)
print(ans_list[:-1])

Submission status: Time Limit Exceeded

Solution code:
# 1からNまでの数字それぞれの約数を求める
# Nから(大きい値から)見ていき、1であれば入れる
# 数字iを入れた場合、iの約数の数を+1
# それぞれの数はdictで保持する

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

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

ans_num = 0
ans_list = ""
for i in range(N):
    tmp = N - i
    s = 0
    for j in range(tmp, N):
        if (j + 1) % tmp == 0:
            s += ans[j]

    if s % 2 != A[tmp - 1]:
        ans[tmp - 1] = 1
        ans_num += 1
        ans_list += str(tmp)
        ans_list += " "


print(ans_num)
print(ans_list[:-1])

Submission status: Time Limit Exceeded

Solution code:
# 1からNまでの数字それぞれの約数を求める
# Nから(大きい値から)見ていき、1であれば入れる
# 数字iを入れた場合、iの約数の数を+1
# それぞれの数はdictで保持する

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

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

ans_num = 0
for i in range(N):
    tmp = N - i
    s = 0
    for j in range(tmp, N):
        if (j+1) % tmp == 0:
            s += ans[j]

    if s % 2 != A[tmp - 1]:
        ans[tmp - 1] = 1
        ans_num += 1


print(ans_num)
ans_list = ""
for i in range(N):
    if ans[i] == 1:
        ans_list += str(i + 1)
        if i != N - 1:
            ans_list += " "

print(ans_list)

Submission status: Time Limit Exceeded

Solution code:
# 1からNまでの数字それぞれの約数を求める
# Nから(大きい値から)見ていき、1であれば入れる
# 数字iを入れた場合、iの約数の数を+1
# それぞれの数はdictで保持する

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

table = [0 for _ in range(N)]
ans = [0 for _ in range(N)]

for i in range(N):
    tmp = N - i
    s = 0
    for j in range(tmp, N):
        if (j+1) % tmp == 0:
            s += ans[j]

    if s % 2 != A[tmp - 1]:
        ans[tmp - 1] = 1


print(sum(ans))
ans_list = ""
for i in range(N):
    if ans[i] == 1:
        ans_list += str(i + 1)
        if i != N - 1:
            ans_list += " "

print(ans_list)

Submission status: Time Limit Exceeded

Solution code:
# 1からNまでの数字それぞれの約数を求める
# Nから(大きい値から)見ていき、1であれば入れる
# 数字iを入れた場合、iの約数の数を+1
# それぞれの数はdictで保持する

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

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

dic = {}
ans = [0 for _ in range(N)]
for i in range(N):
    tmp = N - i
    if tmp in dic:
        if dic[tmp] % 2 != A[tmp-1]:
            dic[tmp] += 1
            ans[tmp - 1] = 1
            divs = divisor(tmp)
            for div in divs:
                if div in dic:
                    dic[div] += 1
                else:
                    dic[div] = 1

    else:
        if A[tmp-1] == 1:
            dic[tmp] = 1
            ans[tmp - 1] = 1
            divs = divisor(tmp)
            for div in divs:
                if div in dic:
                    dic[div] += 1
                else:
                    dic[div] = 1
        else:
            dic[tmp] = 0

print(sum(ans))
ans_list = ""
for i in range(N):
    if ans[i] == 1:
        ans_list += str(i + 1)
        if i != N - 1:
            ans_list += " "

print(ans_list)

Submission status: Time Limit Exceeded

Solution code:
# 1からNまでの数字それぞれの約数を求める
# Nから(大きい値から)見ていき、1であれば入れる
# 数字iを入れた場合、iの約数の数を+1
# それぞれの数はdictで保持する

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

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    table.sort()
    return table

dic = {}
ans = [0 for _ in range(N)]
for i in range(N):
    tmp = N - i
    if tmp in dic:
        if dic[tmp] % 2 != A[tmp-1]:
            dic[tmp] += 1
            ans[tmp - 1] = 1
            divs = divisor(tmp)
            for div in divs:
                if div in dic:
                    dic[div] += 1
                else:
                    dic[div] = 1

    else:
        if A[tmp-1] == 1:
            dic[tmp] = 1
            ans[tmp - 1] = 1
            divs = divisor(tmp)
            for div in divs:
                if div in dic:
                    dic[div] += 1
                else:
                    dic[div] = 1
        else:
            dic[tmp] = 0

print(sum(ans))
ans_list = ""
for i in range(N):
    if ans[i] == 1:
        ans_list += str(i + 1)
        if i != N - 1:
            ans_list += " "

print(ans_list)

Submission status: Time Limit Exceeded

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+=str(b)+' '
  else:
    if a[b-1]==0:
      ans[b]+=1
      S+=1
      t+=str(b)+' '
      

print(S)
if S>0:
  
  print(t)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
C = [0 for i in range(N)]
for i in range(N-1, -1, -1):
  n = 2 * (i + 1)
  c = 0
  while n <= N:
    c ^= C[n-1]
    n += (i + 1)
  if c != A[i]:
    C[i] = 1
print(sum(C))
ans = ""
for i in range(N):
  if C[i] == 1:
    if ans == "":
      ans = ans + str(i+1)
    else:
      ans = ans + " " + str(i+1)
if ans:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
C = [0 for i in range(N)]
for i in range(N-1, -1, -1):
  n = 2 * (i + 1)
  c = 0
  while n <= N:
    c += C[n-1]
    n += (i + 1)
  if (c - A[i]) % 2 == 1:
    C[i] = 1
print(sum(C))
ans = ""
for i in range(N):
  if C[i] == 1:
    if ans == "":
      ans = ans + str(i+1)
    else:
      ans = ans + " " + str(i+1)
if ans:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=[0]+A
B=[]
for i in range(N):
  k=N-i 
  c=0
  for j in range(k,N+1,k):
    if j in B:
      c+=1
      c%=2
  if A[k]!=c:
    B.append(k)
    
print(len(B))
for i in range(len(B)):
  print(B[-(i+1)])

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
A = [int(n) for n in input().split()]
ans_list = []

for n in range(2**N):
    for i in range(1, N+1):
        count = 0
        b = []
        for j in range(i, N+1):
            if j % i == 0 and (n & (1 << (j-1))) :
                count += 1
                b.append(str(j))

        if A[i-1] == count % 2:
            ans_list.append((count, b))
            continue
        else:
            break
    else:
        print(ans_list[0][0])
        print(' '.join(ans_list[0][1]))
        sys.exit(0)

    continue

print(-1)

Submission status: Time Limit Exceeded

Solution code:
from copy import copy
n=int(input())
a=[0]+list(map(int,input().split()))
ans=[0]*(n+1) 
for i in range(n//2+1,n+1):
    ans[i]=a[i]
for j in reversed(range(1,n//2+1)):
    k=2
    count=0
    j_copy=copy(j)
    a_j=a[j]
    while True:
        count+=ans[k*j_copy]
        k+=1
        if k*j_copy>n:
            break
    if count%2==a_j:
        ans[j]+=0
    else:
        ans[j]+=1
temp=[]
for i in range(1,n+1):
  if ans[i]==1:
    temp.append(str(i))
print(ans.count(1))
print(" ".join(temp))

Submission status: Time Limit Exceeded

Solution code:
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())
aas = list(map(int, input().split()))

res = [0]*n
cnts = [0]*n
for i in reversed(range(n)):
    if aas[i] == 0:
        if cnts[i]%2 != 0:
            res[i] = 1
            for j in make_divisors(i+1):
                cnts[j-1] += 1
    else:
        if cnts[i]%2 == 0:
            res[i] = 1
            for j in make_divisors(i+1):
                cnts[j-1] += 1

res_tmp = sum(res)
print(res_tmp)
if res_tmp:
    res_tmp = ""
    for i in range(n):
        if res[i] == 1:
            res_tmp += str(i+1) + " "
    print(res_tmp[:-1])

Submission status: Time Limit Exceeded

Solution code:
def divs(num):
    ans = []
    for i in range(1,int(num**(1/2)+1)):
        if num%i == 0:
            ans += [i,num//i]
    return set(ans)
n = int(input())
a = list(map(int,input().split()))
fin = []
ans = [0]*(n+1)
for i in range(n,0,-1):
    # print(i,a[i-1],ans[i])
    if a[i-1]^ans[i]:
        fin += [i]
        div = divs(i)
        # print(div)
        for j in div:
            ans[j] ^= 1
print(len(fin))
print(*fin)

Submission status: Time Limit Exceeded

Solution code:
#create date: 2020-07-07 11:19

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    b = [0] * n
    for i in range(n, 0, -1):
        cnt = 0
        for j in range(1, n+1):
            if j // i == 0:
                cnt += b[j-1]
        
        if cnt == a[i-1]:
            continue
        elif cnt + 1 == a[i-1]:
            b[i-1] = 1
        else:
            print(-1)
            quit()
    #print(b)
    print(sum(b))
    for i, bi in enumerate(b):
        if bi == 1:
            print(i+1, end=" ")



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in range(n-1,-1,-1):
    if totals[i]%2==a[i]:
        continue
    else:
        ans[i]+=1
        tmp=1
        while tmp*tmp<=i+1:
            if (i+1)%tmp==0:
                totals[tmp-1]+=1
                if tmp !=(i+1)//tmp:
                    totals[((i+1)//tmp)-1]+=1

            tmp+=1


cnt=ans.count(1)

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

    print(*b)