Problem:


Score : 400 points

Problem Statement

Given is a number sequence A of length N.

Find the number of integers i \left(1 \leq i \leq N\right) with the following property:

For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Constraints

All values in input are integers.

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

1 \leq A_i \leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer.

Sample Input 1

5
24 11 8 3 16

Sample Output 1

3

The integers with the property are 2, 3, and 4.

Sample Input 2

4
5 5 5 5

Sample Output 2

0

Note that there can be multiple equal numbers.

Sample Input 3

10
33 18 45 28 8 19 89 86 2 4

Sample Output 3

5



Sample input:
5
24 11 8 3 16


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
n = int(input())
lst = list(map(int,input().split()))
arr = np.array(lst)
lst.sort()
check = ['t']*n
s = 1
i = 0
while True:
  if i == n-1:
    break
  else:
    for k in range(i,n):
      if lst[k] % lst[i] == 0:
        check[k] = 'f'
    if lst[i+1] == lst[i]:
        s -= 1
    j = i+1
    while j <= n:
      if check[j] == 'f':
        pass
      else:   
        s += 1
        i = j
        break
      j += 1  
      if j == n:
        print(s)
        sys.exit()
    
    

print(s)

Submission status: Time Limit Exceeded

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

checked = [0 for _ in range(N)]
nums.sort()
answer = N
for i, num in enumerate(nums):
  if checked[i] == 1:
    continue
  else:
    if i == N-1:
      break
    same = False
    for j in range(i+1, N):
      if nums[j]%num == 0 and checked[j] == 0:
        checked[j] = 1
        answer -= 1
        if nums[j] == num:
          same = True
    if same:
      answer -= 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
ndiv = []
cnt = 10**6 + 1 
while a:
  flg = True
  b = a.pop(0)
  if b % cnt == 0:
    continue
  if a:
    if b % a[0] == 0:
      cnt = b
      continue
  for k in ndiv:
    if b % k == 0:
      flg = False
      break
  if flg:
    ndiv.append(b)
print(len(ndiv))

Submission status: Time Limit Exceeded

Solution code:
import numba
from numba import njit, b1, i4, i8, f8
import numpy as np  # noqa

N = int(input())
A = np.array([int(x) for x in input().split()], dtype=np.int32)


@njit((i4[:], ), cache=True)
def main(A):
    count = np.zeros(10**6 + 10, np.int32)
    for x in A:
        count[::x] += 1
    ret = 0
    for x in A:
        ret += count[x] == 1
    return ret


print(main(A))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

def merge(s, t):
    u = []

    while s + t:
        
        if s == [] or t == []:
            return u + s + t

        if s[0] <= t[0]:
            u.append(s[0])
            s = s[1:]
        else: # s0 > t0
            u.append(t[0])
            t = t[1:]

    return u

while len(A) > 1:
    B = []
    for i in range(len(A) // 2):
        B.append(merge(A[2 * i], A[2 * i + 1]))
    if len(A) % 2 == 1:
        B.append(A[len(A) - 1])
    A = B

A = A[0]
check = [True for _ in range(N)]

for i in range(N):
    if check[i] == True:
        a = A[i]
        for j in range(i + 1, N):
            if check[j] == True:
                if A[j] % a == 0:
                    check[j] = False
                    if j == i + 1:
                        if A[j] <= a:
                            check[i] = False

ans = check.count(True)
                            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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()))
data = [0] * (10**6+1)
for i in range(n):
  data[A[i]] += 1
for i in range(n):
  divisors = make_divisors(A[i])
  for divi in divisors:
    if  data[divi] != (1 if A[i] == divi else 0):
      # print(i,divi)
      break
  else:
    count += 1
    # print(i)
print(count)

# print(data[:25])

Submission status: Time Limit Exceeded

Solution code:
#D
from sys import stdin
def main():
    readline=stdin.readline
    n = int(readline())
    a = list(map(int,readline().split()))
    count=0
    for i in a:
        num_div=0
        for j in a:
            if i%j==0:
                num_div+=1
        if num_div==1:
            count+=1
    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
#D
n = int(input())
a = list(map(int,input().split()))
count=0
for i in a:
    num_div=0
    for j in a:
        if i%j==0:
            num_div+=1
    if num_div==1:
        count+=1
print(count)

Submission status: Time Limit Exceeded

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

for i in a:
  if l[i] == 0:
    l[i] = 1
    for j in range(i*2, max(a)+1, i):
      l[j] = -1
  else:
    l[i] = -1
print(l.count(1))

Submission status: Time Limit Exceeded

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

for i in a:
  if l[i] == 0:
    l[i] = 1
    for j in range(i*2,max(a)+1,i):
      l[j] = -1
  else:
    l[i] = -1
print(l.count(1))

Submission status: Time Limit Exceeded

Solution code:
#D
n = int(input())
a = list(map(int,input().split()))
count=0
for i in range(len(a)):
    num_div=0
    for j in range(len(a)):
        if i != j:
            if a[i]%a[j]==0:
                num_div+=1
  
    if num_div==0:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
A=sorted(A)
maxA=max(A)
ans=0
so_list=[1]*(maxA+1)
index=0
for i in range(N):
    now=A[i]
    if so_list[now]==1:
        index=0
        while(index+now<=maxA):
            so_list[index+now]=0
            index+=now
        if A.count(now)==1:
            ans+=1
            #print(now)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
S=Counter(A)
T=set(S)
# print(S)
# print(T)
# 篩？
ct=0
L=list(S.keys())
L.sort()
# print(L)

for i in range(len(L)):
    a=L[i]
    if a not in T:
        continue
    T.remove(a)
    if S.get(a)==1:
        ct+=1
    tmp=T.copy()
    # print(tmp)
    for n in T:
        if n%a==0:
            tmp.difference_update({n,})
    T=tmp
print(ct)

Submission status: Time Limit Exceeded

Solution code:
def main():

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

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

    for i in range(N):
        Ai = A[i]
        for j in range(i+1, N):
            Aj = A[j]
            if Ai%Aj == 0:
                count[i] += 1
            if Aj%Ai == 0:
                count[j] += 1

    ans = 0
    for i in range(N):
        if count[i] == 0:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
A_list = list(map(int, input().split()))
A_list_max  = max(A_list)
C = Counter(A_list)

cnt = 0
A_baisu = []

for i in range(N):
    k = A_list_max//A_list[i]
    #print(k, A_list_max)
    if C[A_list[i]] >= 2:
        A_baisu.append(A_list[i])
    if k >= 2:
        for j in range(2, k+1):
            if A_list[i]*j in A_list:
                A_baisu.append(A_list[i]*j)

A_baisu = list(set(A_baisu))
#print(A_baisu)

for i in range(len(A_baisu)):
    cnt += A_list.count(A_baisu[i])
ans = N - cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
A_list_min = sorted(A_list)

cnt = 0
A_baisu = []

for i in range(N-1):
    k = A_list_min[-1]//A_list_min[i]
    if A_list_min[i] == A_list_min[i+1]:
        A_baisu.append(A_list_min[i])
    if k >= 2:
        for j in range(2, k+1):
            if A_list_min[i]*j in A_list_min:
                A_baisu.append(A_list_min[i]*j)

A_baisu = list(set(A_baisu))
#print(A_baisu)

for i in range(len(A_baisu)):
    cnt += A_list_min.count(A_baisu[i])
ans = N - cnt        

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
dp=[0]*(10**6+1)
cnt=[0]*(10**6+1)
ans=0

for elem in a:
    cnt[elem]+=1
    for i in range(elem*2,10**6+1,elem):
        dp[i]=1
        
for elem in a:
    if cnt[elem]!=1:
        dp[elem]=1

for elem in a:
    if dp[elem]==0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
dp=[0]*(10**6+1)
cnt=[0]*(10**6+1)
ans=0

for elem in a:
    cnt[elem]+=1
    for i in range(elem*2,10**6+1,elem):
        dp[i]=1
for elem in a:
    if cnt[elem]!=1:
        dp[elem]=1

for elem in a:
    if dp[elem]==0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
dp=[True]*(10**6+1)
cnt=[0]*(10**6+1)
ans=0

for elem in a:
    cnt[elem]+=1
    for i in range(elem*2,10**6+1,elem):
        dp[i]=False
for elem in a:
    if cnt[elem]!=1:
        dp[elem]=False

for elem in a:
    if dp[elem]:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
dp=[True]*(10**6+1)
cnt=[0]*(10**6+1)
ans=0

for elem in a:
    cnt[elem]+=1
    for i in range(elem*2,10**6+1,elem):
        dp[i]=False


for elem in a:
    if dp[elem] and cnt[elem]==1:
        ans+=1
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):
  B = []
  d = 0
  for j in range(N):
    B.append(A[i] % A[j])
    if B.count(0) > 1:
      d = 1
      break
  if d == 0:
    c += 1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

A.sort()
a = A.copy()

ans_list = list()
A_len =len(A)

while A_len != 0:
    for i in range(A_len-1):
        if A[i+1] % A[0] == 0:
            a.remove(A[i+1])
    if A_len != 1:
        if A[0] == A[1]:
            a.remove(A[0])
            A = a.copy()
            A_len = len(A)
        else:
            ans_list.append(A[0])
            a.remove(A[0])
            A = a.copy()
            A_len = len(A)
    else:
            ans_list.append(A[0])
            a.remove(A[0])
            A = a.copy()
            A_len = len(A)
    
ans = len(ans_list)
print(ans)

Submission status: Time Limit Exceeded

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

if N == 1:
  print(1)
  exit()

flag=[1]*N
for i in range(N-1):
  if flag[i]==0:continue
  for j in range(i+1,N):
    if flag[j]==0:continue
    if j==i+1 and A[j]==A[i]:
      flag[i] = 0
    if A[j]%A[i] == 0:
      flag[j] = 0
      
print(sum(flag))

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    candidate_idices = set([i for i in range(N)])
    for i in range(N):
        next_canditates = set([])
        if i not in candidate_idices:
            continue
        for j in candidate_idices:
            if i == j:
                next_canditates.add(j)
                continue
            if A[j] % A[i] != 0:
                next_canditates.add(j)
            if A[i] == A[j]:
                next_canditates.discard(i)
        candidate_idices = next_canditates
    print(len(candidate_idices))

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    sorted_A = sorted(A)
    candidate_idices = list(range(N))
    for i in range(N):
        next_canditates = []
        for j in candidate_idices:
            if i == j:
                next_canditates.append(j)
                continue
            if sorted_A[j] % sorted_A[i] != 0:
                next_canditates.append(j)
        candidate_idices = next_canditates
    print(len(candidate_idices))

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    candidate_idices = set([i for i in range(N)])
    for i in range(N):
        blackset = set([])
        for j in candidate_idices:
            if i == j:
                continue
            if A[j] % A[i] == 0:
                blackset.add(j)
        candidate_idices -= blackset
    print(len(candidate_idices))

if __name__ == "__main__":
    solve()

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())
A = list(map(int, input().split()))
A = sorted(A, reverse = True)
counter = 0
for i in A:
  re = True
  if A.count(i) >= 2:
    continue
  for x in range(A.index(i)+1, N):
    if i % A[x] == 0:
      re = False
      break
#  div_l = make_divisors(i)
#  del div_l[len(div_l)-1]
#  for x in div_l:
#    if x in A:
#      re = False
#      break
  if re == True:
    counter += 1
print(counter)

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())
A = list(map(int, input().split()))
counter = 0
for i in A:
  re = True
  if A.count(i) >= 2:
    continue
  div_l = make_divisors(i)
  del div_l[len(div_l)-1]
  for x in div_l:
    if x in A:
      re = False
      break
  if re == True:
    counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
A.sort()
div = [0] * 1000001
num = [0] * 1000001
for a in A:
    num[a] += 1
ans = 0
for a in A:
    hoge = 0
    if num[a] == 1:
        hoge = 1
        m = int(math.sqrt(a))
        for i in range(1, m+1):
            if a % i == 0 and (div[i] == 1 or div[int(a/i)] == 1):
                hoge = 0
    div[a] = 1
    ans += hoge
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
counts = [0] * (10 ** 6 + 1)
for a in A:
    counts[a] += 1
others = set(A)
ans = 0
for a in A:
    delete = False
    if counts[a] == 1:
        others.discard(a)
        delete = True
    i = 1
    while i * i <= a:
        if a % i == 0 and (i in others or (a // i) in others):
            break
        i += 1
    else:
        ans += 1
    if delete:
        others.add(a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
counts = [0] * (10 ** 6 + 1)
for a in A:
    counts[a] += 1
Aset = set(A)
ans = 0
for a in A:
    others = set(Aset)
    if counts[a] == 1:
        others.discard(a)
    i = 1
    while i * i <= a:
        if a % i == 0 and (i in others or (a // i) in others):
            break
        i += 1
    else:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
ans = 0
for i, a in enumerate(A):
    others = set(A[:i] + A[i+1:])
    i = 1
    while i * i <= a:
        if a % i == 0 and (i in others or (a // i) in others):
            break
        i += 1
    else:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
valid = [True] * len(A)
sqrt = A[len(A)-1] // 2
stop = -1
for i in range(len(A)):
    if A[i] > sqrt:
        stop = i
        break
    if valid[i] == False:
        continue
    for j in range(i+1, len(A)):
        if valid[j] == False:
            continue
        if A[j] % A[i] == 0:
            valid[j] = False
        if A[j] == A[i]:
            valid[i] = False
if stop != -1:
    cur = A[stop]
    for i in range(stop+1, len(A)):
        if cur == A[i]:
            valid[i-1] = valid[i] = False
        else:
            cur = A[i]
print(valid.count(True))

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
valid = [True] * len(A)
sqrt = A[len(A)-1] // 2
stop = -1
for i in range(len(A)):
    if A[i] > sqrt:
        stop = i
        break
    if valid[i] == False:
        continue
    for j in range(i+1, len(A)):
        if A[j] % A[i] == 0:
            valid[j] = False
        if A[j] == A[i]:
            valid[i] = False
if stop != -1:
    cur = A[stop]
    for i in range(stop+1, len(A)):
        if cur == A[i]:
            valid[i-1] = valid[i] = False
        else:
            cur = A[i]
print(valid.count(True))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
count = [True] * len(A)
sames = []
nums = []
for i in range(len(A)):
    if count[i] == False:
        continue
    divided = False
    for num in nums:
        if A[i] == num and not num in sames:
            sames.append(num)
        if A[i] % num == 0:
            divided = True
            count[i] = False
            break
    if not divided:
        nums.append(A[i])
        
print(count.count(True)-len(sames))

Submission status: Time Limit Exceeded

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

div_list = [0]*N
cnt = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if A[j] % A[i] == 0 and div_list[j] == 0:
            div_list[j] += 1
            cnt += 1

print(N - cnt)

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
cnt=[0]*(a[-1]+1)
while a:
  m=a.pop(0)
  cnt[m]+=1
  i=0
  while i<len(a):
    if a[i]%m==0 and a[i]//m>1:
      a.pop(i)
      continue
    i+=1
ans=0
for ci in cnt:
  ans+=(1 if ci==1 else 0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
dp = {}
for i in A:
    dp[i] = True
A.sort()
for i in range(N):
    if dp[A[i]]:
        for j in range(i+1, N):
            if A[j] % A[i] == 0:
                dp[A[j]] = False
counter = 0
for key in dp.keys():
    if dp[key]:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]

for d in A:
    A  = [x for x in A if (x == d or x % d != 0)]
each = Counter(A)
result = 0
for key in each:
    if each[key] == 1:
         result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
list.sort(A,reverse=True)
COUNT=N
for i in range(N):
    for j in range(N):
        if (A[i]%A[j]==0)and(i!=j):
            COUNT-=1
            break
print(COUNT)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
COUNT=N
for i in range(N):
    for j in range(N):
        if (A[i]%A[j]==0)and(i!=j):
            COUNT-=1
            break
print(COUNT)

Submission status: Time Limit Exceeded

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

n = I()
a = LI()
a.sort()
li = [True]*n
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if a[j] == a[i]:
      li[i] = False
    if a[j]%a[i] == 0:
      li[j] = False
print(li.count(True))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
res = 0
while A:
    if len(A) == 1:
        res += 1
    else:
        if A[0] != A[1]:
            res += 1
    t = A[0]
    NA = []
    for a in A:
        if a % t != 0:
            NA.append(a)
    A = NA[:]
print(res)

Submission status: Time Limit Exceeded

Solution code:
# Not Divisible

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

A.sort()
ok = []

while 0 < len(A):
    div = True
    for i in range(1, len(A)):
        if A[0] == A[i]:
            div = False
            A[i] = 0
        elif A[i] % A[0] == 0:
            A[i] = 0
    if div:
        ok.append(A[0])
    A[0] = 0
    A = list(filter(lambda a: 0 < a, A))

print(len(ok))

Submission status: Time Limit Exceeded

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

#Aiは、Ai以外の任意の(すべての)Ajで割り切れない
unans = 0
for i in a:
  count = 0
  for j in a:
    if i % j == 0:
      count += 1
    if count >= 2:
      unans += 1
      break
   
print(n - unans)

Submission status: Time Limit Exceeded

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

#Aiは、Ai以外の任意の(すべての)Ajで割り切れない
unans = 0
for i in a:
  count = 0
  for j in a:
    if i % j == 0:
      count += 1
    if count >= 2:
      unans += 1
      break
   
print(n - unans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    a.sort()
    a = tuple(a)
    TorF = [0] * (a[-1] + 1)
    for ae in a:
        TorF[ae] = 1
    for i1 in range(n - 1):
        if TorF[a[i1]]:
            t = a[i1] * 2
            while t <= max(a):
                TorF[t] = 0
                t += a[i1]
        if a[i1 + 1] == a[i1]:
            TorF[a[i1]] = 0
    r = sum(TorF)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    if n == 1:
        print(1)
        sys.exit()
    if n == 2:
        if a[0] == a[1]:
            print(0)
            sys.exit()
        elif max(a) % min(a) == 0:
            print(0)
            sys.exit()
        else:
            print(2)
            sys.exit()
    a.sort()
    notdiv = [True] * n
    for i1, ae in enumerate(a):
        if notdiv[i1]:
            t = ae * 2
            while t <= max(a):
                if t in a:
                    notdiv[a.index(t)] = False
                t += ae
    if a[0] == a[1]:
        notdiv[0] = False
    if a[-1] == a[-2]:
        notdiv[-1] = False
    for j1 in range(1, n - 1):
        if a[j1-1] == a[j1] or a[j1] == a[j1+1]:
            notdiv[j1] = False
    r = sum(notdiv)
    print(r)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
from copy import deepcopy
def main():
    n, *a = map(int, read().split())
    if n == 1:
        print(1)
        sys.exit()
    if n == 2:
        if a[0] == a[1]:
            print(0)
            sys.exit()
        elif max(a) % min(a) == 0:
            print(0)
            sys.exit()
        else:
            print(2)
            sys.exit()
    a.sort()
    notdiv = [True] * n
    for i1, ae in enumerate(a):
        if notdiv[i1]:
            for i2 in range(i1+1, n):
                notdiv[i2] = notdiv[i2] and a[i2] % ae != 0
    if a[0] == a[1]:
        notdiv[0] = False
    if a[-1] == a[-2]:
        notdiv[-1] = False
    for j1 in range(1, n - 1):
        if a[j1-1] == a[j1] or a[j1] == a[j1+1]:
            notdiv[j1] = False
    r = sum(notdiv)
    print(r)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
from copy import deepcopy
def main():
    n, *a = map(int, read().split())
    if n == 1:
        print(1)
        sys.exit()
    if n == 2:
        if a[0] == a[1]:
            print(0)
            sys.exit()
        elif max(a) % min(a) == 0:
            print(0)
            sys.exit()
        else:
            print(2)
            sys.exit()
    a.sort()
    notdiv = [True] * n
    for i1, ae in enumerate(a):
        if notdiv[i1]:
            for i2 in range(i1+1, n):
                if notdiv[i2]:
                    notdiv[i2] = a[i2] % ae != 0
    if a[0] == a[1]:
        notdiv[0] = False
    if a[-1] == a[-2]:
        notdiv[-1] = False
    for j1 in range(1, n - 1):
        if a[j1-1] == a[j1] or a[j1] == a[j1+1]:
            notdiv[j1] = False
    r = sum(notdiv)
    print(r)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# Not Divisible

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

A.sort()

for i in range(len(A) - 1):
    if A[i] == 0:
        continue
    a = A[i]
    for j in range(i + 1, len(A)):
        if a == A[j]:
            A[i] = 0
        if A[j] == 0:
            continue
        if A[j] % a == 0:
            A[j] = 0

print(sum(map(lambda a: 0 < a, A)))

Submission status: Time Limit Exceeded

Solution code:
#同じものが2つ以上含まれていた場合、それらを除外する
#最小値で割っていき、割り切れるものを除外する
#最小値を除外し、次の最小値で割っていき、割り切れるものを除外する
#最小値が最大値の半分より大きくなるところで探索終了

import numpy as np

N = int(input())

x = np.array(np.uint64(input().split()))
#print(x)


def hantei_3(list_1, length):
    list_2, counts = np.unique(list_1, return_counts=True)
    list_6 = list_2[counts > 1]
    #if np.count_nonzero(list_3) == 0:
    #    return 0
    #else:
        #print(list_3)
    list_3 = list_1
    count_list = []
    count_1 = 0
    for k in range(N):
        if np.count_nonzero(list_3) == 0:
            break
        else:
            min_1 = np.amin(list_3)
            max_1 = np.amax(list_3)
            if min_1 > max_1 / 2:
                list_4, counts_2 = np.unique(list_3, return_counts=True)
                list_4 = list_4[counts_2 == 1]
                count_1 = np.count_nonzero(list_4)
                #print(list_4)
                #print(count_1)
                break
            else:
                list_3 = list_3[list_3 % min_1 != 0]
                #print(list_3)
                if min_1 not in list_6:
                    count_list.append(min_1)
                    #print(count_list)
    count_2 = len(count_list)
    #print(count_2)
    count_3 = count_1 + count_2
    return count_3

print(hantei_3(x, N))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

x = np.array(np.uint64(input().split()))
#print(x)

def hantei_5(length, list_1):
    list_2 = np.array([True for i in np.arange(N) if np.count_nonzero(
        list_1[i] % list_1 == 0) == 1])
    #print(list_2)
    count = np.count_nonzero(list_2)
    return count

print(hantei_5(N,x))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

x = np.array(tuple(map(int, input().split())))


def hantei_2(length, list_1):
    count = 0
    #list_2 = list_1
    for i in list_1:
        if np.count_nonzero(i % list_1 == 0) == 1:
            count += 1
    return count


def hantei_3(length, list_1):
    count = 0
    #list_2 = list_1
    for i in np.arange(N):
        if np.count_nonzero(list_1[i] % list_1 == 0) == 1:
            count += 1
    return count

def hantei_4(length, list_1):
    list_2 = np.array([True for i in np.arange(N) if np.count_nonzero(
        list_1[i] % list_1 == 0) == 1])
    print(list_2)
    count= np.count_nonzero(list_2)
    print(count)


def hantei_5(length, list_1):
    list_2 = np.array([True for i in np.arange(N) if np.count_nonzero(
        list_1[i] % list_1 == 0) == 1])
    #print(list_2)
    count = np.count_nonzero(list_2)
    return count

print(hantei_5(N,x))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

x = np.array(tuple(map(int, input().split())))


def hantei_2(length, list_1):
    count = 0
    #list_2 = list_1
    for i in list_1:
        if np.count_nonzero(i % list_1 == 0) == 1:
            count += 1
    return count


def hantei_3(length, list_1):
    count = 0
    #list_2 = list_1
    for i in np.arange(N):
        if np.count_nonzero(list_1[i] % list_1 == 0) == 1:
            count += 1
    return count

print(hantei_3(N,x))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

x = np.array(tuple(map(int, input().split())))


def hantei_2(length, list_1):
    count = 0
    #list_2 = list_1
    for i in list_1:
        if np.count_nonzero(i % list_1 == 0) == 1:
            count += 1
    return count


print(hantei_2(N,x))

Submission status: Time Limit Exceeded

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

A.sort()

B=[0]*( A[N-1] +1 )

for i in A:
  if(B[i]==0):
    for j in A[A.index(i)+1:]:
      if(j%i==0):
        B[j] += 1


count=0
for i in A:
  if(B[i]==0):
    count +=1


print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A = list(map(int,input().split() ))
 
count=0
for i in range(N):
  for j in range(N):
    if(i!=j):
      if(A[i]%A[j] == 0):
        count += 1
        break
print(N-count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

x = np.array(tuple(map(int, input().split())))


def hantei(length, list_1):
    count = 0
    for i in np.arange(length):
        break_hantei = 0
        for j in np.arange(length):
            if i != j and list_1[i] % list_1[j] == 0:
                break_hantei = 1
                break
        #if i != j:
        if break_hantei == 0:
            #print((list_1[i],list_1[j]))
            count += 1
    return count


def hantei_2(length, list_1):
    count = 0
    list_2 = list_1
    for i in list_1:
        list_3 = np.where(i % list_2 == 0, 1, 0)
        #print(list_3)
        if np.sum(list_3) == 1:
            count += 1
    return count

#print(N)
#print(x)
print(hantei_2(N,x))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

x = np.array(tuple(map(int, input().split())))


def hantei(length, list_1):
    count = 0
    for i in np.arange(length):
        break_hantei = 0
        for j in np.arange(length):
            if i != j and list_1[i] % list_1[j] == 0:
                break_hantei = 1
                break
        #if i != j:
        if break_hantei == 0:
            #print((list_1[i],list_1[j]))
            count += 1
    return count

#print(N)
#print(x)
print(hantei(N,x))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

x = np.array(tuple(map(int, input().split())))


def hantei(length, list_1):
    count = 0
    for i in range(length):
        break_hantei = 0
        for j in range(length):
            if i != j and list_1[i] % list_1[j] == 0:
                break_hantei = 1
                break
        #if i != j:
        if break_hantei == 0:
            #print((list_1[i],list_1[j]))
            count += 1
    return count

#print(N)
#print(x)
print(hantei(N,x))