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: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()
A = getList()

list_a = [0] * (10 ** 6 + 1)
list_b = [0] * (10 ** 6 + 1)

for i in A:
    list_a[i] += 1

ans = 0
for i in range(1, 10 ** 6 + 1):
    if not list_a[i]:
        continue
    if list_a[i] == 1 and not list_b[i]:
        ans += 1
    for j in range(1, 10 ** 6 + 1):
        if i * j > 10 ** 6 + 1:
            break
        list_b[i * j] = 1
print(ans)

Submission status: Runtime Error

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

ans_list = [[1, 0] for i in range(100001)]
for i in range(N):
    now = A[i]
    ans_list[now][1] += 1
    for j in range(2*now, 100001, now):
        ans_list[j][0] = 0

count = 0
for i in range(N):
    now = A[i]
    if ans_list[now][0] == 1 and ans_list[now][1] == 1:
        count += 1
        
print(count)

Submission status: Runtime Error

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

for i in range(n):
    flag = 0
    if i == 0:
        if a[0]==a[1]:
            l.append(a[0])
            continue
        else:
            l.append(a[0])
            continue

    if a[i] in l:
        continue

    for j in l:
        if a[i]%j:
            flag = 1
            break
        else:
            break

    if flag:
        l.append(a[i])
        if i == 0:
            if a[i] != a[i+1]:
                num += 1
        elif i == n-1:
            if a[i] != a[i-1]:
                num += 1
        elif a[i] != a[i+1] and a[i] != a[i-1]:
            num += 1

print(num)

Submission status: Runtime Error

Solution code:
n = int(input())
search = list(map(int,input().split()))
search.sort()
dp = [1]*(search[-1]+1)
if search[0] == 1:
    if search[1] != 1:
        print(1)
    else:
        print(0)
else:
    for i in search:
        k = 2*i
        while k <= search[-1]:
            if dp[k]:
                dp[k] = 0
                k += i
            else:
                break
    ans = 0
    flag = False
    j = -1
    for i in search:
        if flag:
            if i != j:
                flag = False
                ans -= dp[j]
        else:
            if i == j:
                flag = True
            else:
                ans += dp[i]
                j = i
    
print(ans-dp[search[-1]] if flag else ans)

Submission status: Runtime Error

Solution code:
import itertools
from collections import Counter
h = int(input())
if h == 1:
	print(1)
	exit()
a = list(map(int,input().split()))
t = Counter(a)
b = []
for i, j in t.most_common():
	if j == 1:
		b.append(i)
bset = set(a)

def sieve(n):
	ret = []
	divlis = [-1]*(n+1)  # 何で割ったかのリスト(初期値は-1)
	flag = [True]*(n+1)
	flag[0] = False
	flag[1] = False
	ind = 2
	while ind <= n:
		if flag[ind]:
			ret.append(ind)
			ind2 = ind**2
			while ind2 <= n:
				flag[ind2] = False
				divlis[ind2] = ind
				ind2 += ind
		ind += 1
	#何で割ったかのリストを取得したいとき, divlisも出力する
	return ret

k = sieve(1000)

def pfact(m):
	pf = {}
	cnt = 0
	i = k[cnt]
	while m > 1:
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
		cnt += 1
		i = k[cnt]
	if m>1 : pf[m]=1
	return pf

def makediv(n):
	s = pfact(n)
	k = [range(i+1) for i in s.values()]
	ansl = []
	for i in itertools.product(*k):
		ans = 1
		for n, j in enumerate(s.keys()):
			ans *= (j**i[n])
		ansl.append(ans)
	ansl.sort()
	return ansl

ans = 0
for i in b:
	t=makediv(i)
	t.remove(i)
	mode = 1
	for l in t:
		if l in bset:
			mode = 0
			break
	if mode:
		ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
MAX = int(2e5)


n = int(input())
lis = list(map(int,input().split()))
lis2 = [0]*MAX
# lis.sort()
# m = max(lis)
ans = 0
for num in lis:
    lis2[num] += 1

for num in lis:
    for i in range(num*2, MAX, num):
        if lis2[i] > 0:
            lis2[i] += 1

print(len([i for i in lis if lis2[i] == 1]))

Submission status: Runtime Error

Solution code:
import bisect
import copy
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
table = [True for i in range(N)]
cands = [i for i in range(N)]
k = 0
while k < len(cands):
    i = cands[k]
    new_cands = copy.deepcopy(cands)
    if i < N-1 and A[i] == A[i+1]:
        idx = bisect.bisect_left(new_cands, i)
        del new_cands[idx]
    for j in cands[k+1:]:
        if A[j] % A[i] == 0:
            idx = bisect.bisect_left(new_cands, j)
            del new_cands[idx]
    if len(new_cands) > 0 and new_cands[k] == cands[k]:
        k += 1
    cands = copy.deepcopy(new_cands)
print(len(cands))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
a = sorted(list(a))
ma = max(a)

div = defaultdict(bool)
count = 0
for i in range(n):
    b = a[i]
    if div[b]:
        count += 1
    else:
        for j in range(1,ma//b+1):
            div[j*b] = True
        if(i<n and a[i] == a[i+1]):
            count += 1

if(n == 1):
    print(0)
else:
    print(n-count)

Submission status: Runtime Error

Solution code:
from numba import njit
@njit()
def check(s, a, next):
    if a==next:
        return False
    x = 1
    while a>=x*x:
        if a%x==0:
            if x in s:
                return False
            if a//x in s:
                return False
        x += 1
    return True

n = int(input())
al = list(map(int, input().split()))
al.sort()

s = set()
res = 0
for i in range(n):
    a = al[i]
    next = -1
    if i<n-1:
        next = al[i+1]
    if check(s,a,next):
        res += 1
    s.add(a)
print(res)

Submission status: Runtime Error

Solution code:
def main():
  n=int(input())
  a=sorted(map(int,input().split()))
  maxa=a[-1]+1
  tf=[False]*maxa
  r=0
  n-=1
  for i in range(n):
    a_i=a[i]
    if tf[a_i] ==False:
      for j in range(a_i,maxa,a_i):
        tf[j]=True
      if a_i < a[i+1]:
        r+=1
  if tf[n] ==False:
    r+=1
  print(r)
main()

Submission status: Runtime Error

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()
    M=10**6+5
    dp=[1]*M
    A.sort()
    L=[A[0]]
    for i in range(1,N):
        if A[i]!=L[-1]:
            L.append(A[i])
        else:
            dp[A[i]]=0
            
    for i in range(len(L)):
        temp=L[i]*2
        if dp[temp]==1:
            while temp<M-2:
                dp[temp]=0
                temp+=L[i]
        
    ans=0        
    for i in range(len(L)):
        if dp[L[i]]==1:
            ans+=1
            
            
    

         
            
    print(ans)
                
    
    


main()

Submission status: Runtime Error

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

f = [True for _ in range(1000000)]

for i in range(n):
  if(f[a[i]-1] == False):
    continue
    
  k = a[i]
  while(k <= 1000000):
    f[k-1] = False
    k += a[i]
    
c = 0
for i in range(n):
  if(f[a[i]]):
    f[a[i]] = False
    c += 1
    if(i+1 != n):
      if(a[i] == a[i+1]):
        c -=1
print(c)

Submission status: Runtime Error

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

a.sort()

import collections
c = collections.Counter(a)

d=[]
for ck,cv in c.items():
    if cv>=2:
       d.append(ck) 
dset=set(d)
    
aa=[]

while True:
    aa.append(a[0])
    a2=[]
    for i in range(1,len(a)):
        if a[i]%a[0]!=0:
            a2.append(a[i])
#    a=a2.copy()
    if len(a2)==0:
        break

    aa.append(a2[0])
    a=[]
    for i in range(1,len(a2)):
        if a2[i]%a[0]!=0:
            a.append(a2[i])
#    a=a2.copy()
    if len(a)==0:
        break

aaset=set(aa)
aaset=aaset-dset    
print(len(aaset))

Submission status: Runtime Error

Solution code:
import numpy as np

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

ans=0
A.sort()

f=[0]*1000005

for i in A:
    f[i]+=1

for i in range(1,1000001,1):
    if f[i]==0:
        continue
    j=i+i
    while j<=1000000:
        f[j]+=f[i]
        j=j+i

for i in A:
    if f[i]==1:
        ans+=1


print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
if len(set(A)) == 1:
    print(0)
    exit()

from collections import Counter
c = Counter(A)

count = 0
NMAX = 2 * 10 ** 5 + 10
L = [True] * (NMAX + 1)
for k, v in c.items():
    p = k
    if L[p]:
        for i in range(p * 2, NMAX + 1, p):
            L[i] = False

for k, v in c.items():
    if v > 1: continue
    if L[k] == True:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())
i = 0
while a:
    if a.count(a[0]) == 1:
        i+=1
    a = list(filter(lambda x: x%a[i] >0,a))
print(i)

Submission status: Runtime Error

Solution code:
#import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

def yakusuu(n):
    #約数リスト生成,バラバラに出るので.sort()を使う必要あるかも
    #PyPy推奨
    yakusuu_list = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yakusuu_list.append(i)
            if i != n // i:
                yakusuu_list.append(n//i)
    return yakusuu_list

def ok(wa,waaa,item,bl):
    m=yakusuu(item)
    #print(m)
    if waaa[item-1]==True:
        bl.append(item-1)
        return

    waaa[item-1]=True

    for jtem in m:
        if jtem!=item and waaa[jtem-1]==True:
            bl.append(item-1)
            return

    waaa[item-1]=True
    #print(item,waaa[:25])
    return

def main():
    n=int(input())
    a=list(map(int, input().split()))
    #print(sorted(a))
    a.sort()
    wa=[a[0]]
    waaa=[False]*(a[-1])
    bl=[]

    for item in a:
        ok(wa,waaa,item,bl)

    #import collections
    print(waaa.count(True)-len(set(bl)))
    return
    #print(max(0,len(wa)-len(set(bl))))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
if len(set(A)) == 1:
    print(0)
    exit()

from collections import Counter
c = Counter(A)

count = 0
NMAX = 2 * 10 ** 3 + 10
L = [True] * (NMAX + 1)
for k, v in c.items():
    p = k
    if L[p]:
        for i in range(p * 2, NMAX + 1, p):
            L[i] = False

for k, v in c.items():
    if v > 1: continue
    if L[k] == True:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ng = [0] * 1050000
ans = 0
for i in range(n):
    if i:
        if a[i] == a[i-1]:
            continue
    else:
        if a[i] == a[i+1]:
            continue
    if not ng[a[i]]:
        ans += 1
        for j in range(1, 1050000//a[i]):
            ng[a[i]*j] = 1
print(ans)

Submission status: Runtime Error

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

    max_a = a[-1]
    dp = [True] * max_a

    for i in a:
        x = 1
        while i * x <= max_a:
            dp[i * x] = False
            x += 1

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
import bisect

def sortedexist(list,x):
    if bisect.bisect_left == bisect.bisect_right:
        return False
    else:
        return True

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
done = dict()
for a in A:
    done[a] = False
dp = [False] * max(A) + 1

for a in A:
    if done[a]:
        dp[a] = True
    else:
        for j in range(2,1 + (max(A) // a)):

            dp[a*j] = True
        done[a] = True
print(sum([dp[a] == False for a in A ]))

Submission status: Runtime Error

Solution code:
from collections import deque

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

A.sort()
d = deque()
for i in range(N-1):
    if A[i] != A[i+1]:
        d.append(A[i])
if A[N-1] != A[N-2]:
    d.append(A[N-1])

ans = 0
max_A = max(A)
ban = [0]*max_A
while len(d):
    num = d.popleft()
    if ban[num] != 1:
        ans += 1
        ban_num = num
        while ban_num <= max_A:
            ban[ban_num] = 1
            ban_num += num

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
vec = np.array([int(i) for i in input().split()])
counter = 0
matrix = np.zeros((N, N))
for i in range(N):
    matrix[i] = vec%vec[i]
for j in range(N):
    if list(matrix.T[j]).count(0) == 1:
        counter += 1
print(counter)

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
an = list(map(int, sys.stdin.readline().rstrip().split()))
bn = sorted(an, reverse=True)

count=1
if bn[-1]==bn[-2]:
    count=0
#print(bn)

for i in range(n-1):
    count += 1
    for j in range(i+1, n):
#        print(i, j)

        if bn[i]%bn[j]==0:
#            print('No')

            count -= 1

            break
#    print('ok', count)

print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
import bisect

def sortedexist(list,x):
    if bisect.bisect_left == bisect.bisect_right:
        return False
    else:
        return True

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
done = dict()
for a in A:
    done[a] = False
dp = [False] * 10**6 + 1

for a in A:
    if done[a]:
        dp[a] = True
    else:
        for j in range(2,1 + (10**6 // a)):
            dp[a*j] = True
        done[a] = True
print(sum([dp[a] == False for a in A ]))

Submission status: Runtime Error

Solution code:
import bisect

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

if A[0] != A[1]:
  ans += 1

for i in range(N - 1,-1,-1):
  sup = A[i] // 2 
  ind = bisect.bisect(A,sup)
  ind = max(ind,i)
  for j in range(0,ind):
    if A[i] % A[j] == 0:
      ans -= 1
      break

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 1:
    print(1)
elif A[0] == 1 and A[1] == 1:
    print(0)
elif A[0] == 1:
    print(1)
else:
    Eratos = [False]*1000001
    ans = 0
    for i in range(N):
        if Eratos[A[i]]:
            ans += 1
        else:
            for j in range(A[i], 1000001, A[i]):
                Eratos[j] = True
print(N-ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
import bisect

def sortedexist(list,x):
    if bisect.bisect_left == bisect.bisect_right:
        return False
    else:
        return True

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
done = dict()
for a in A:
    done[a] = False
dp = [False] * 10**6 + 1

for a in A:
    if done[a]:
        dp[a] = True
    else:
        for j in range(2,10**6 // a):
            dp[a*j] = True
        done[a] = True
print(sum([dp[a] == False for a in A ]))

Submission status: Runtime Error

Solution code:
from collections import Counter
import bisect

def sortedexist(list,x):
    if bisect.bisect_left == bisect.bisect_right:
        return False
    else:
        return True

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
done = dict()
for a in A:
    done[a] = False
dp = [False] * 10**6

for a in A:
    if done[a]:
        dp[a] = True
    else:
        for j in range(2,10**6 // a):
            dp[a*j] = True
        done[a] = True
print(sum([dp[a] == False for a in A ]))

Submission status: Runtime Error

Solution code:
# coding: utf-8
#import numpy as np
import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import bisect
from queue import PriorityQueue
import itertools
from itertools import accumulate
from copy import deepcopy
from collections import Counter
import heapq
import random
import time
import os
import sys
import datetime
from functools import lru_cache
from functools import reduce
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
alphabet="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):
    if b:print("yes")
    else:print("no")
def Yn(b):
    if b:print("Yes")
    else:print("No")
def YN(b):
    if b:print("YES")
    else:print("NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(bbool,ret1,ret2):
    if bbool:return ret1
    else:return  ret2
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    return c.join(A)
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def pm(x):
    return x//abs(x)
def inputintlist(): 
    return list(map(int,input().split()))
def inputfloatlist(): 
    return list(map(float,input().split()))
def tozero(A):
    ret=[None]*len(A)
    for a in range(len(A)):
        ret[a]=A[a]-1
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])#[cost,x]
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def heron(a,b,c):
    s=(a+b+c)/2
    S=s(s-a)(s-b)(a-c)
    S=math.sqrt(S)
    return S
def getAreaOfTriangle(x1,y1,x2,y2,x3,y3):
    a=geted(x1,y1,x2,y2)
    b=geted(x2,y2,x3,y3)
    c=geted(x3,y3,x1,y1)
    return heron(a,b,c)






######################################################################################################


N=int(input())
A=inputintlist()
S=set()
for k,v in Counter(A).items():
    if v>1:
        S.add(k)
num=2*10**5+100
warikireru=[False]*num
A.sort()
ans=0
for a in A:
    if warikireru[a]==False:
        if a not in S:ans+=1
    now=a
    for b in range(now,num,now):
        warikireru[b]=True
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    import bisect
    n = int(input())
    A = list(map(int,sys.stdin.readline().rstrip().split()))
    A.sort()

    ans = 0
    a_max = A[-1]
    note = [True]*(a_max+1)
    for j in range(n):
        a = A[j]
        if note[a]:
            if j != n-1 and A[j]==A[j+1]:
                ans-=1
            ans+=1
            for i in range(a,a_max+1):
                if i%a==0:
                    note[i] = False

        
    
    print(ans)
main()

Submission status: Runtime Error

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()
    M=10**6+5
    dp=[1]*M
    A.sort()
    L=[A[0]]
    for i in range(1,N):
        if A[i]!=L[-1]:
            L.append(A[i])
        else:
            dp[A[i]]=0
            
    for i in range(len(L)):
        temp=L[i]*2
        if dp[temp]==1:
            while temp<M:
                dp[temp]=0
                temp+=L[i]
        
    ans=0        
    for i in range(len(L)):
        if dp[L[i]]==1:
            ans+=1
            
            
    

         
            
    print(ans)
                
    
    


main()

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
i = 0
while a:
    if a.count(a[0]) == 1:
        i+=1
    a = list(filter(lambda x: x%a[i] >0,a))
print(i)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split(' '))))
ans = 0
L = [1]*(10**6+1)
for i in sorted(A.keys()):
    if A[i] > 1:
        continue
    ans += L[i]
    for j in (i,10**6+1,i):
        L[j] = 0
print(ans)

Submission status: Runtime Error

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()

    y = [0] * (10**6 + 1)
    A = []
    for x in sys.stdin.readline().split():
        x = int(x)
        A.append(x)
        y[x] += 1

    ans = 0
    for i in range(N):
        x = A[i]
        if x > 1:
            if y[1] : continue
        if y[x] > 1: continue

        f = 1
        for j in range(2,int(math.sqrt(x))+1):
            if y[j] or y[x//j]:
                if i % j == 0
                    f = 0
                    break
        ans += f

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

cA = collections.Counter(A)
new_A = []
for a in A:
    if cA[a] == 1:
        new_A.append(a)
A = new_A

A.sort()
# print(A)

answers = set(A)
for i in range(N):
    dame = set()
    for a in answers:
        if a == A[i]:
            continue
        if a % A[i] == 0:
            dame.add(a)
    answers = answers - dame
ans = len(answers)
print(ans)

Submission status: Runtime Error

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

N = int(input())
A = list(map(int, input().split()))
A.sort() # 一応

count = 0
while 1:
    new = []
    b = A[0]
    for a in A[1:]:
        if a % b > 0: # bで割れなければ続投
            new.append(a)
    A = new
    # かぶりがないなら
    if b < A[1]:
        count += 1


print(count)

Submission status: Runtime Error

Solution code:
n = int(input())

a = list(map(int, input().split()))
a.sort()
valid = valid = [1] * n
ret = 0
tgt = 0

#print(a)

while True:
	num = a[tgt]
	valid[tgt] = 0
#	print("tgt",tgt,num)

	for i in range((tgt+1),n):
#		print(a[i],num,a[i]%num)
		if(valid[i] == 0):
			continue
		if(a[i]%num == 0):
			valid[i] = 0
	
	ret += 1
	
	for i in range((tgt+1),n):
		if(valid[i] == 1):
			tgt = i
			break


	if(i==n-1):
		if(tgt == n-1):
			ret+=1
		break

if(ret==1):
	print(0)
else:
	print(ret)

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.readline
 
import numpy as np
from collections import Counter
 

N = int(input())
A = np.array(readline().split())
count = Counter(A)
A = np.array([
    a for a, c in count.items() if c == 1
])
 
if len(A) != 0:
    A = np.sort(A)

i = 0
while True:
    if len(A) == 0:
        break
    pre = A
    a = A[i]
    A = np.delete(A, np.where((A % a == 0) & (A != a)))
    i += 1
    if i >= len(A):
        break

print(len(A))

Submission status: Runtime Error

Solution code:
n = int(input())
ns = list(map(int, input().split()))
ans = 0
from collections import Counter
c = Counter(ns)
dubbles = set([key for key, value in c.items() if value >= 2])
ns = sorted(set(ns))
a = [True] * n
for i in range(n):
    if not a[i]:
        continue
    for j in range(i + 1, n):
        if not a[j]:
            continue
        if ns[j] % ns[i] == 0:
            a[j] = False
print(sum(a))

Submission status: Runtime Error

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

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

A.sort()

is_ok = [False] * (10 ** 5 + 1)
is_exist = [False] * (10 ** 5 + 1)

for a in A:
    if is_exist[a]:
        is_ok[a] = False
    else:
        is_exist[a] = True
        is_ok[a] = True
        for i in range(1, 10 ** 5 // a + 1):
            if a * i <= 10 ** 5:
                is_exist[a * i] = True

print(is_ok.count(True))

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort(reverse=True)
count = 0
for n in np.array(range(N)):
    print(f"N:{n}")
    if n != N-1:
        L_s = L[n+1:]
    else:
        L_s = L[n:]
    print(f"L_s:{L_s}")
    for l_s in L_s:
        print(l_s)
        if L[n]%l_s == 0:
            break
    else:
        count += 1

print(count)

Submission status: Runtime Error

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

b = sorted(set(a))

if len(b) == 1:
    print(0)
else:    
    stack = []
    stack.append(b[0])
    for i in range(1,n):
        flag = 0
        for e in stack:
            if b[i] % e == 0:
                flag = 1
                break
        if flag == 0:
            stack.append(b[i])

    print(len(stack))