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:
from collections import Counter
from itertools import product

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    def getMinPFs(n):
        isPrimes = [False]*2 + [True]*(n-1)
        minPFs = [1] + list(range(1, n+1))
        for d in range(2, int(n**0.5)+1):
            if isPrimes[d]:
                minPFs[d] = d
                for x in range(d*d, n+1, d):
                    isPrimes[x] = False
                    if minPFs[x] == x:
                        minPFs[x] = d
        return minPFs

    def getPrimeFactors(x, minPFs):
        anss = []
        while minPFs[x] > 1:
            anss.append(minPFs[x])
            x //= minPFs[x]
        return anss

    maxA = max(As)
    minPFs = getMinPFs(maxA)
    As.sort()

    cntA = Counter(As)

    ans = 0
    setA = set()
    for A in As:
        if cntA[A] == 1:
            PFs = getPrimeFactors(A, minPFs)
            cnt = Counter(PFs)
            ps = list(cnt.keys())
            es = [range(cnt[p]+1) for p in ps]
            L = len(ps)
            for nums in product(*es):
                d = 1
                for i in range(L):
                    d *= ps[i]**nums[i]
                if d in setA:
                    break
            else:
                ans += 1

        setA.add(A)

    print(ans)


solve()

Submission status: Time Limit Exceeded

Solution code:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n = inp()
x = ip()
dt = {}
for i in x: dt[i] = dt.get(i,0)+1
mark = {}
for i in x:
    if dt[i] >= 2:
        mark[i] = 0
    j = 2
    mx = max(x)+1
    while i*j < mx:
        mark[i*j] = 0
        j += 1
ans = 0
for i in x:
    ans += mark.get(i,1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

N = int(sys.stdin.readline())
A = np.array(sorted(map(int, sys.stdin.readline().split(' '))))

dp = np.ones(N, dtype=np.bool)

for i in range(N - 1):
    if not dp[i]:
        continue
    if not np.any(dp[i:]):
        break
    dp[i + 1:] &= (A[i + 1:] % A[i] != 0)
    dp[i] &= (A[i] != A[i + 1])

print(np.count_nonzero(dp))

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
from numba import jit

@jit
def main():
    n=int(input().rstrip())
    a=sorted([int(i) for i in input().split()])
    maxn=10**6+1
    dp=[True]*(maxn)
    cnt=[0]*(maxn)
    ans=0
    for i in a:
        if dp[i]:
            cnt[i]+=1
            for j in range(i*2,maxn,i):
                dp[j]=False

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

if __name__=="__main__":main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
an = np.array([int(a) for a in input().split()], dtype=np.int64)
#dd = np.reshape(an, (n, 1))
res = 0

tmp = np.zeros(n, dtype=np.int64)

#grid = np.tile(an, (n, 1))
#div = np.remainder(grid, dd)
#div = np.count_nonzero(div, axis=0)
#res = div[div == (n-1)].size

for i in range(n):
    nt = np.remainder(an, an[i])
    #print(nt)
    t = np.where(nt == 0)
    tmp[t[0]] += 1

#print(tmp)
print(np.sum(tmp[tmp == 1]))

Submission status: Time Limit Exceeded

Solution code:
import sys
#from numba import jit

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def cc(v, pp,dame):
	if v == pp[-1]:
		return False, -1
	if dame and dame[-1] == v:
		return False, 0
	
	for p in pp:
		if v % p == 0:
			return False, 0
		if v < 2*p:
			return True, 0
	return True, 0
			
def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	al.sort()
	pp=[al[0]]
	dame=[]
	n_same=0
	n_same_set=set()
	for v in al[1:]:
		tf, vv = cc(v, pp, dame)
		if tf:
			pp.append(v)
		elif dame and v != dame[-1]:
			dame.append(v)
		if vv == -1 and pp[-1] not in n_same_set:
			n_same_set.add(pp[-1])
			n_same += vv
	print(len(pp) + n_same)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

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=10**6+10
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: Time Limit Exceeded

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    A = LMIIS()
    A.sort()
    ans = 0
    count = defaultdict(int)
    for a in A:
        count[a] += 1




    def make_divisors(n):
        lower_divisors , upper_divisors = deque(),deque()
        for i in range(1,int(n**0.5)+1):
            if n % i == 0:
                lower_divisors.append(i)
                if i != n // i:
                    upper_divisors.appendleft(n//i)
            i += 1
        upper_divisors
        return lower_divisors + upper_divisors




    F = deque()
    for a in A:
        F.append(make_divisors(a))
    ans = 0
    Not_Divisible = [False] * (max(A)+1)
    for f in F:
        for d in f:
            if Not_Divisible[d]:
                break
        else:
            num = f.pop()
            Not_Divisible[num] = True
            if count[num] == 1:
                ans += 1
    print(ans)

    
main()

Submission status: Time Limit Exceeded

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

l=[0]*N
n=0
for x in A:
    for i in range(N):
        if x%A[i]!=0:
            l[n]+=1
    n+=1

print(l.count(N-1))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


import itertools
import math
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(math.sqrt(n)) + 1):
       if temp%i == 0:
           cnt=0
           while temp%i == 0:
               temp //= i
               arr.append(i)

    arr.append(temp)

    ret = set()
    for val in itertools.product([0, 1], repeat = len(arr)):
        cal = 1
        for i, v in enumerate(val):
            if v == 1:
                cal *= arr[i]

        ret.add(cal)
    return ret - set([n])


def main():
    n = input_int()
    a_list = input_to_int_tuple()

    a_set = set(a_list)
    cnt = 0

    import collections
    for val, val_cnt in collections.Counter(a_list).items():
        if val_cnt > 1:
            continue

        flg = False
        for i in factorization(val):
            if i in a_set:
                flg = True
                break

        if not flg:
            cnt += 1

    # for i, val in enumerate(a_sorted_list):
    #     flg = True
    #
    #     for devide_val in a_sorted_list[:i]:
    #         if val % devide_val == 0:
    #             flg = False
    #
    #     if flg:
    #         cnt += 1

    return cnt


if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

N = int(sys.stdin.readline())
A = np.array(sorted(map(int, sys.stdin.readline().split(' '))))

dp = np.ones(N, dtype=np.bool)

for i in range(N - 1):
    if not dp[i]:
        continue
    dp[i + 1:] &= (A[i + 1:] % A[i] != 0)
    dp[i] &= (A[i] != A[i + 1])

print(np.count_nonzero(dp))

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
#import random
#import time
from collections import defaultdict, Counter

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

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    #N = 20
    #A = [random.randint(1, int(1e6)) for _ in range(int(N))]
    N = int(input())
    A = [int(c) for c in input().split(' ')]
    #t1 = time.time()
    dup_cnt = Counter(A)
    dup = set(x for x in dup_cnt if dup_cnt[x] > 1)
    A_set = set(A)
    if 1 in A_set:
        if 1 in dup:
            print('0')
        else:
            print('1')
        exit()
    A = list(A_set)
    for t in (2,3,5,7):
        if t in A_set:
            A = [x for x in A if x%t != 0 or x==t]
    N = len(A)
    A.sort()
#    B = [factorization(x) for x in A]
#    B.sort()

    d = defaultdict(list)
    B = []
    for x in A:
        x_fac = factorization(x)
        B.append(x_fac)
        for y in x_fac:
            d[y[0]].append(x)
    assert len(A)==len(B)
    #print(A)
    #print(B)
    #print(d)
    not_divided = set()
    for i in range(N):
        bi = A[i]
        bi_fac = B[i]
        can_divide = False
        for y in bi_fac:
            for a in d[y[0]]:
                if bi % a == 0 and bi != a:
                    #print(a,bi)
                    can_divide = True
                    break
                elif a > bi:
                    break
            if can_divide:
                break
        if can_divide or bi in dup:
            continue
        else:
            not_divided.add(bi)
    #print(A)
    #print(dup)
    #print(not_divided)
    print(len(not_divided))
    #print(time.time() - t1)


if __name__ == "__main__":
    main()

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 = count -1
			break
print(count)

Submission status: Time Limit Exceeded

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

for i, a_i in enumerate(a):
    if memo[i] == 'No':
        continue
    for h in [j for j in range(i+1, n) if a[j] % a_i == 0]:
        memo[h] = 'No'
    if i != n-1 and a_i == a[i+1]:
        continue
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    c=0
    for i in range(n):
        for j in range(n):
            if (a[i]//a[j])*a[j]==a[i]:
                if i!=j:
                    break
            if j==n-1:
                c+=1
    print(c)
main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
import pprint



sys.setrecursionlimit(2147483647)
INF = 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
A = sorted(LI())
s = set()
B = [0] * (10 ** 6 + 1)
for a in A:
    i = 2
    if a in s:
        continue
    while a * i <= 10 ** 6:
        B[a * i] = 1
        i += 1

cnt = Counter(A)
ans = 0
for a in A:
    if B[a] == 0 and cnt[a] == 1:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys 
import math

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split()))
A.sort()
# print(A)

ans = 0 
invalid = set()
for i in range(N):
    if A[i] in invalid:
        continue

    flag = True
    for j in range(i+1, N):
        if A[j] in invalid:
            continue
        
        # print(A[i], A[j])
        if A[j] % A[i] == 0:
            invalid.add(A[j])
        if A[i] == A[j]:
            # print("break")
            #break
            flag = False
    else:
        if flag:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if A[i] % A[j] == 0:
            break
    else:
        good_i.append(i)

print(len(good_i))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def make_divisors(n):  # 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

def main():
    # 約数
    N = ir()
    A = lr()
    A.sort()
    answer = 0
    bl = [False] * (A[-1]+1)
    used = set()
    for i, a in enumerate(A):
        if i < N-1 and a == A[i+1]:
            bl[a] = True
            continue
        if a in used:
            continue
        used.add(a)
        divs = make_divisors(a)
        flag = True
        for x in divs:
            if bl[x]:
                flag = False
                break
        bl[a] = True
        if flag:
            answer += 1

    print(answer)

main()

Submission status: Time Limit Exceeded

Solution code:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n = inp()
x = ip()
dt = {}
for i in x: dt[i] = dt.get(i,0)+1
mark = [1]*(1000001)
for i in x:
    if dt[i] >= 2:
        mark[i] = 0
    j = 2
    mx = max(x)+1
    while i*j < mx:
        mark[i*j] = 0
        j += 1
ans = 0
for i in x:
    ans += mark[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = Counter(map(int, input().split()))
nums = sorted(list(a.keys()))
ans = n
for i, num in enumerate(nums):
    if a[num] > 1:
        ans -= a[num]
        continue
    if i == 0:
        continue
    search_range = nums[:i]
    for i in search_range:
        if num % i == 0:
            ans -= a[num]
            break
print(ans)

Submission status: Time Limit Exceeded

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

factor = []
B = []
duplicated = set()

for a in sorted(A):
    for f in factor:
        if a == f:
            duplicated.add(a)
        if a % f != 0:
            continue
        else:
            break
    else:
        factor.append(a)


# for i in range(len(factor)):
#     for j in range(len(factor)):
#         if i == j:
#             continue
#         if A[i] % A[j] != 0:
#             cnt += 1
#     if cnt == N - 1:
#         ans += 1
#     cnt = 0

print(len(factor) - len(duplicated))

Submission status: Time Limit Exceeded

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

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

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

    A = new


print(count)

Submission status: Time Limit Exceeded

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

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()
A = sorted(A)

B = [0]*(10**6+1)
C = [0]*(10**6+1)
for i in range(len(A)):
    if B[A[i]] == 0:
        C[A[i]] = 1
    for j in range(A[i]*2,10**6+1,A[i]):
        B[j] = 1

from collections import Counter

c = Counter(A)

for i in c.keys():
    if c[i] >= 2:
        C[i] = 0

print(sum(C))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
  N = int(input())
  not_divisible_list = [True]*N
  not_divisible_count = N
  A = [int(x) for x in input().split(" ")]
  A.sort()
  # set_A = set(A)

  for i, a_t in enumerate(A):
    if not_divisible_list[i] == False:
      continue
    for j, a in enumerate(A[i+1:]):
      if a_t==a:
        not_divisible_list[i] = False
      if a%a_t==0:
        not_divisible_list[i+1+j] = False
  print(not_divisible_list.count(True))

if __name__ == "__main__":
  resolve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections
input()

def no_Divisible(num,num_set):
    for row in num_set-{num}:
        if num%row==0:
            return 0
    return 1

count = 0
input_list = list(map(lambda x:int(x),input().split(" ")))
koho = {key for key,value in collections.Counter(input_list).items() if value==1}
visi = set(input_list)

for num in koho:
    if no_Divisible(num,visi):
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import Counter
def input():
    return sys.stdin.readline()[:-1]
def main():
    N = int(input())
    A = sorted(list(map(int,input().split())))
    U = [0]*(max(A)+1)
    for e in A:
        U[e] += 1
    ans = 0
    for k in range(1,max(A)+1):
        if U[k] == 1:
            ans += 1
        if U[k] > 0:
            for l in range(2*k,max(A)+1,k):
                if U[l] > 0:
                    U[l] += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    A = LMIIS()
    A.sort()
    ans = 0
    count = defaultdict(int)
    for a in A:
        count[a] += 1




    def make_divisors(n):
        lower_divisors , upper_divisors = deque(),deque()
        for i in range(1,int(n**0.5)+1):
            if n % i == 0:
                lower_divisors.append(i)
                if i != n // i:
                    upper_divisors.appendleft(n//i)
            i += 1
        upper_divisors
        return lower_divisors + upper_divisors




    F = deque()
    for a in A:
        F.append(make_divisors(a))
    ans = 0
    Not_Divisible = [False] * (max(A)+1)
    for f in F:
        for d in f:
            if Not_Divisible[d]:
                break
        else:
            Not_Divisible[f[-1]] = True
            if count[f[-1]] == 1:
                ans += 1
    print(ans)
    dbg(F)
    dbg(Not_Divisible)
    
main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
flag = [1]*n
ans = 0

for i in range(n):
    for j in range(i,n):
        if i == j:
            pass
        else:
#             print(i,j)
            amari = a[i]%a[j]
            amari2 = a[j]%a[i]
            if amari == 0: # 次のaiへ
                flag[i] = 0 # 割り切れる物を見つけた印
            if amari2 == 0: # 次のaiへ
                flag[j] = 0 # 割り切れる物を見つけた印

ans = sum(flag)
# print(flag)
print(ans)