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:
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

N=int(input())
A=list(map(int, input().split()))
ans=0
for i in range(N):
	l=divisor(A[i])
	
	if set(A[:i]).isdisjoint(l) and set(A[i+1:]).isdisjoint(l):
		ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


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]
 
 
def main():
    N = int(input().strip())
    divisors = set()
    ans = set()
    l = [int(i) for i in input().strip().split()]
    heapq.heapify(l)
 
    for _ in range(N):
        n = heapq.heappop(l)
 
        if n in divisors:
            if n in ans:
                ans.remove(n)
            continue
 
        divs = make_divisors(n)
 
        for d in divs:
            if d in divisors:
                divisors.add(n)
                break
        else:
            divisors.add(n)
            ans.add(n)
 
    return len(ans)
 

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

Submission status: Time Limit Exceeded

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

for i in range(n):
  for j in range(n):
    if i==j:
      continue
    if a[i]%a[j]==0:
      x[i]+=1
print(x.count(0))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=int(input())
aaa=list(map(int,input().split()))
aaa.sort()
aa=deque(aaa)
count=0
while aa:
    a=aa.popleft()
    if len(aa)!=0:
        b=aa.popleft()
    else:
      b=float("inf")
    if a!=b:
        count+=1
    if b!=float("inf"):
      aa.appendleft(b)
    k=len(aa)
    co=0
    while co!=k:
      t=aa.popleft()
      co+=1
      if t%a!=0:
        aa.append(t)
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 a[i] % a[j] == 0 and i != j:
            count += 1
            break

print(n-count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import collections
import bisect


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


N = int(input())

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

A.sort()

ans = 0
ans = N
for i in range(N):
    divs = divisor(A[i])
    Set = set(A[:i])
    #print(A[i], "divs", divs)
    if i < N - 1:
        if A[i] == A[i + 1]:
            ans -= 1
            continue

    for d in divs:
        if i != 0:
            if d in Set:
                ans -= 1
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = input()
    a = list(map(int, input().split()))
    bt = [0] * len(a)
    a.sort()
    for i in range(0, len(a)):
        for j in range(0, len(a)):
            if (a[j] // 2) > a[i]:
                break
            if i == j or bt[i] == 1:
                continue
            if a[j] % a[i] == 0:
                bt[j] = 1
            if a[i] % a[j] == 0:
                bt[i] = 1
    print(len(bt) - sum(bt))



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
numbers = [int(i) for i in input().split()]
b = 0
x = len(numbers[0:a])
for i in range(0, x):
    for j in range(0, x):
        if numbers[i]%numbers[j] == 0 and i != j:
            break
    else:
        b += 1
print(b)

Submission status: Time Limit Exceeded

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

if n==1:
    print(1)
    sys.exit()
"""
def mergesort(a):
    def _merge_sort(a, left: int, right: int):
        if left < right:
            center = (left+right)//2

            _merge_sort(a,left,center)
            _merge_sort(a,center+1,right)

            #pは前半部をbuffにコピーする際のインデックス、jで取り出す
            p=j=0
            i=k=left

            #配列の前半部をbuffにコピー
            while i <= center:
                buff[p]=a[i]
                p+=1
                i+=1

            #後半部をコピーされた前半部と比較、小さい方をaに格納していく
            while i<= right and j < p:
                if buff[j] <= a[i]:
                    a[k]=buff[j]
                    j+=1
                else:
                    a[k]=a[i]
                    i+=1
                k+=1

            while j < p:
                a[k] =buff[j]
                k+=1
                j+=1

    n=len(a)
    #merge結果を一時的に格納
    buff=[None]*n
    _merge_sort(a,0,n-1)
    del buff

mergesort(a)
"""
def fsort(a,max):
    n=len(a)
    f=[0]*(max+1)
    b=[0]*n

    for i in range(n):
        f[a[i]]+=1
    for i in range(1, max+1):
        f[i]+=f[i-1]
    for i in range(n-1,-1,-1):
        f[a[i]]-=1; b[f[a[i]]]=a[i]
    for i in range(n):
        a[i]=b[i]

fsort(a, 10**6)

if a[0]==1:
    if a[1]==1:
        print(0)
        sys.exit()
    else:
        print(1)
        sys.exit()

if a[0]==a[1]:
    count=0
else:
    count=1

for i in range(n-2):
    if a[i+2]==a[i+1]:
        continue
    if a[i+1]==a[i]:
        continue
    for l in range(i+1):
        if a[i+1]%a[l]==0:
            break
        if i==l:
            count+=1

if a[n-1]!=a[n-2]:
    for i in range(n):
        if a[n-1]%a[i]==0:
            break
        if i==n-2:
            count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    nn = int(input())
    a = {}
    exists = set()
    for i,aa in enumerate(map(int, input().split())):
        if aa not in a:
            a[aa] = i
        else:
            exists.add(aa)
    tt = 0
    for n in a.keys():
        for div in range(1, int(n**0.5)+1):
            if n % div == 0:
                dd = n // div
                if dd != 1 and div in a:
                    break
                if dd != n and dd in a:
                    break
        else:
            if n not in exists:
                tt += 1

    print(tt)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

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 = sorted(list(map(int, input().split())))
cnt = 0
cnt1 = a.count(1)
if cnt1 > 1:
    print(0)
    sys.exit()
elif cnt1 == 1:
    print(1)
    sys.exit()
if n == 1:
    print(1)
    sys.exit()
for i in range(n):
    d = make_divisors(a[i])
    # print(d)
    if i == 0 and a[i] == a[i + 1]:
        continue
    if i == n - 1 and a[i - 1] == a[i]:
        continue
    if i not in [0, n - 1] and (a[i - 1] == a[i] or a[i] == a[i + 1]):
        continue
    if len(d) == 2:
        cnt += 1
        continue
    d = d[:-1]
    for j in d:
        if a[bisect_left(a, j)] == j:
            break
    else:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list_str = input().split()
a_list = [int(a) for a in a_list_str]
cnt = 0
for i in range(len(a_list)):
  cnt_flag = False
  for j in range(len(a_list)):
    if i == j:
      continue
    if (a_list[i] / a_list[j]).is_integer():
      cnt_flag = True
      break
  if cnt_flag:
    cnt += 1
print(n - cnt)

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
a = [int(item) for item in input().split()]

a.sort()

b = copy.deepcopy(a)
flag = []
num = []

for i in range(n):
    if i in flag:
        continue
    for j in range(i+1, n):
        if j in flag:
            continue
        if a[j] % a[i] == 0 and a[j] in b:
            flag.append(j)
            b = [item for item in b if item != a[j]]

print(len(b))

Submission status: Time Limit Exceeded

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

    divisors.sort()
    return divisors

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

if a[0]==1:
    if n>=2 and a[1]==1:
        print(0)
    else:
        print(1)
else:
    ans = 0
    for num in a:
        if a.count(num) >= 2:
            continue
        else:
            cands = set([i for i in a if i!=num])
            divs = set(make_divisors(num))
            if not cands&divs:
                ans+=1
            
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
 
n = int(input())
a = list(map(int, input().split()))
counter = set([])
for i in range(n - 1):
    a_np = np.roll(np.array(a), i + 1)
    counter = counter | set(np.where(a % a_np == 0)[0])
print(n - len(counter))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
counter = Counter(A)
s = sorted(set(A))
if len(A) == 1:
    print(1)
else:
    lst = []
    ans = 0
    for i in range(len(s)):
        m = s[i]/2
        flg = True
        for p in lst:
            if s[i]%p == 0:
                flg = False
                break
            elif m < p:
                break
        if flg:
            lst.append(s[i])
            if counter[s[i]] == 1:
                ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def make_divisors_exist(n):
    #divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if exists[i]:
                if i != n:
                    return True
            #divisors.append(i)
            i2 = n // i
            if i != i2: # choufuku
                if exists[i2]:
                    if i2 != n:
                        return True
                #divisors.append(i2)

    # divisors.sort()
    #return divisors
    return False



input = raw_input
input()
As_0 = map(int, input().split(" "))

out = 0

counter = Counter(As_0)
As = counter.keys()

max_A = max(As)
exists = [False] * (max_A + 1)

for A in As:
    exists[A] = True

for A1, num in counter.items():
    if num >= 2:
        continue
    
    exist = False

    #ds = make_divisors(A1)
    #for d in ds:
    #    if exists[d]:
    #        if d != A1:
    #            exist = True
    exist = make_divisors_exist(A1)

    if not exist:
        out += 1

print(out)

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n = inp()
a = sorted(inpl())
check = [False] * n
ans = 0


class Cell:
    def __init__(self, value):
        self.value = value
        self.prev = None
        self.next = None


prev = Cell(a[0])
now = prev
for i in range(1, n):
    new = Cell(a[i])
    prev.next = new
    new.prev = prev
    prev = prev.next
FLAG = True
while now:
    if not now.next:
        if FLAG:
            ans += 1
        break
    target = now.next
    FLAG = True
    while target:
        if FLAG and target.value == now.value:
            FLAG = False
            ans -= 1
        if target.value % now.value == 0:
            if target.next:
                target.next.prev = target.prev
                target.prev.next = target.next
            else:
                target.prev.next = None
        target = target.next
    ans += 1
    now = now.next
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

ans = 0
while len(A) > 0:
    if not (len(A) > 1 and A[0] == A[1]):
        ans += 1
    A = [a for a in A if a % A[0] != 0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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

rcnt=0
length=len(A)

for i in range(length):
    cnt=0
    for j in range(length):
        if A[i]%A[j]!=0 and A[i]!=A[j]:
            cnt+=1
    if cnt==N-1:
        rcnt+=1
print(rcnt)

Submission status: Time Limit Exceeded

Solution code:
a = []
cnt = 0

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

for i in range(n):
    for j in range(n):
        if not i == j and a[i] % a[j] == 0:
            cnt += 1
            break

print(n-cnt)

Submission status: Time Limit Exceeded

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

def handle(i):
  tmp = list(map(lambda x: i%x, a))
  if tmp.count(0) == 1:
  	return 1
  else:
    return 0

result = 0
tmp = list(map(handle,a))
print(tmp.count(1))

Submission status: Time Limit Exceeded

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

ext_num = 0
ext_dict = {}
ans_list = []
for a_num in a:
    append_flag = True
    if a_num in ans_list:
        if a_num not in ext_dict.keys():
            ext_dict[a_num] = 1
            ext_num = ext_num + 1
        continue
    for ans_num in ans_list:
        if a_num % ans_num == 0:
            append_flag = False
            break
    if append_flag:
        ans_list.append(a_num)

print(len(ans_list) - ext_num)

Submission status: Time Limit Exceeded

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

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

for i in range(n - 1):
    if B[i] == 1:
        if A[i] == A[i + 1]:
            B[i] = 0

print(sum(B))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def solve(A,N):
    value_count=0
    for i in range(N):
        Ai=A[i]
        test_A=Ai%A
        if(list(test_A).count(0)==1):
            value_count+=1
    return value_count
N=int(input())
A= np.array(list(map(int,input().split())))
print(solve(A,N))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    Atemp = list(map(int, input().split()))

    A = sorted(Atemp)

    count = 0
    for i in range(N):
        flag = True
        for j in range(i):
            if A[i] % A[j] == 0:
                flag = False
                break
        if flag and i < N-1:
            if A[i] == A[i+1]:
                flag = False
        if flag:
            count += 1
    
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
  ans = 0
  for i in range(n):
    for j in range(n):
      if a[i] % a[j] == 0 and i != j:
        ans += 1
        break
  print(n-ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
A = list(map(int, input().split()))
c = []
L=[]
for g in range(n):
  L.append(g)
for i, j in itertools.product(L,L):
    if i !=j and A[i]%A[j] == 0:
        c.append(i)
        
c = set(c)

print(n - len(c))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
check_list = [0] * N
def be_can_div(i):
    for j in range(N):
        if i == j:
            continue
        if A[j] % A[i] == 0:
            check_list[i] = 1
        if A[i] % A[j] == 0:
            return False
    return True

count = 0
for i in range(N):
    # print(check_list)
    if check_list[i] == 1:
        continue
    if be_can_div(i):
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import numpy as np
from numba import jit, void


# 標準入力の取得
N = int(input())
A = list(map(int, input().split()))
A = list(sorted(A))
A = np.array(A)


@jit(void(), nopython=True)
def main() -> None:
    # 求解処理
    result = 0
    for i in range(N):
        A_i = A[i]
        if np.sum(A == A_i) > 1:
            continue
        can_divide = False
        for j in range(i):
            A_j = A[j]
            if A_i % A_j == 0:
                can_divide = True
                break
        if not can_divide:
            result += 1

    # 結果出力
    print(result)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#D
N = int(input())
A = list(map(int, input().split()))
A.sort()
counter = 0
for i in range(N):
    can_divide = False
    for j in range(N):
        if i!=j and A[i]%A[j]==0:
            can_divide = True
            break
    if not can_divide:
        counter+= 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
  for j in range(n):
    if i != j and a[i] % a[j] == 0:
      break
    elif j == n-1:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
As=[int(x) for x in input().rstrip('\n').split()]
As2 = sorted(list(set(As)))
res = 0
for i in range(N):
  if len(As2)>0:
    now = As2[0]
    As2=[x for x in As2 if x%now!=0]
    if As.count(now)==1:
      res += 1
  else:
    break
print(res)

Submission status: Time Limit Exceeded

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)]
for i in range(N):
    if table[i]:
        idx = bisect.bisect_left(cands, i)
        del cands[idx]
        if i < N-1 and A[i] == A[i+1]:
            table[i] = False
        new_cands = copy.deepcopy(cands)
        for j in cands:
            if A[j] % A[i] == 0:
                table[j] = False
                idx = bisect.bisect_left(new_cands, j)
                del new_cands[idx]
        cands = copy.deepcopy(new_cands)
print(table.count(True))

Submission status: Time Limit Exceeded

Solution code:
def d():
    import numpy as np
    N = int(input())
    A = np.array(list(map(int, input().split())))
    uniques, counts = np.unique(A, return_counts=True)
    ans = 0

    for i, a in enumerate(uniques):
        if counts[i] > 1:
            continue
        else:
            B = uniques[:i]
            if 0 not in a % B:
                # if 0 not in a % uniques:
                ans += 1

    print(ans)


##########
if __name__ == "__main__":
    d()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
p = list(map(int, input().split()))
count = 0
k = 0

for i in range(n):
    for j in p:
        if p[i] % j == 0 and i != k:
            break
        k += 1
    if(k == n):
        count += 1
    k = 0

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = N
for i in range(N):
    flg = 0
    for j in range(N):
        if i == j :
            continue
        if int(A[i]) % int(A[j]) == 0:
            flg = 1
    if flg == 1:
        ans -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

count=0
isDividable=0

for i in range(n):
  isDividable=0
  l=a[i]/2
  for j in range(n):
    if i != j and (a[j] <= l or a[i] == a[j]) and a[i] % a[j] == 0:
      isDividable=1
      break
  if isDividable==0:
    count=count+1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# D - Not Divisible
import numpy as np
from collections import Counter

N = int(input())
A = list(int(a) for a in input().split())
c = Counter(A)
dbl = set([i[0] for i in c.items() if i[1] >= 2])

A.sort()
A = np.array(A)
ans = 0
for i in range(N):
    if A[i] == 0:
        continue
    elif A[i] not in dbl:
        ans += 1
    B = A % A[i]
    B = B.astype(np.bool)
    A = A * B

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.sort(np.array(list(map(int, input().split()))))
b = np.ones(N, dtype=bool)
for i, ai in enumerate(A):
    if b[i] == 0:
        continue
    b[b] = (A[b] % ai != 0)
    b[i] = (i==N-1) or (A[i]!=A[i+1])
print(b.sum())

Submission status: Time Limit Exceeded

Solution code:
import copy
from collections import Counter

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

counter = Counter(seq)
candidate = set(seq)

count = 0

for x in sorted(candidate):
    if x not in candidate:
        continue

    l = list(sorted(candidate))
    idx = l.index(x)
    for y in l[idx+1:]:
        if y % x == 0:
            candidate.remove(y)

for c in tuple(candidate):
    if seq.count(c) > 1:
        candidate.remove(c)

print(len(candidate))

Submission status: Time Limit Exceeded

Solution code:
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
v=set()
l.sort(reverse=True)
ans=0
for i in range(n):
	c=0
	for j in range(n-1,-1,-1):
		if l[i]<l[j]:
			break
		if  i==j:
			continue
		if l[i]%l[j]==0:
			c=1
			#print(l[j],l[i])
			break
	if c==0:
		ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
tmp = []
flag = [0]*N
for i in range(N):
    f = 0
    for j in range(N):
        if i == j:
            continue
        else:
            if A[i]%A[j]==0:
                f=1
    if f == 0:
        ans += 1
    

print(ans)
# print(tmp)
# print(flag)

Submission status: Time Limit Exceeded

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

L = 0
for n,i in enumerate(a):
    H = 0
    for m,j in enumerate(a):
        if i % j == 0 and n != m:
            H = 1
            break
    if H == 0:
        L+=1
print(L)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
def input(): return sys.stdin.readline()

n=int(input())
a=np.array(list(map(int,input().split())))
 
ans=0
#print(a%(np.array([a for _ in range(n)])).transpose())
 
for i in range(n):
  b=a[i]%a==0
  #print(b)
  if np.count_nonzero(b)==1:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

w = False
count = 0

for i in range(0, len(a_list)):

    w = False

    for j in range(0, len(a_list)) :

        if i != j :
            if a_list[i] % a_list[j] == 0 :
                w = True
                break

    if w == False:
        count = count + 1

print(count)

Submission status: Time Limit Exceeded

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

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

def is_prime(n):
  if n == 1:
    return False
  for i in range(2, int(math.sqrt(n)) + 1):
    if n % i == 0:
      return False
  return True

D = []
E = []

for i, x in enumerate(A):
  Flag = True
  
  if i >= 1 and x == D[-1]:
    E.append(x)
    continue

  if i >= 1 and D[0] != 1 and is_prime(x):
    D.append(x)
    continue
    
  for j in D:
    if x%j == 0:
      Flag = False
      if x == j:
        E.append(x)
      break
    
  if Flag:
    D.append(x)

print(len(set(D)-set(E)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = set(a)

    num = len(a) - len(b)

    count = 0

    a.sort()

    x =  list(itertools.combinations(a,2))

    ansList = []
    
    for i in range(len(x)):
        if x[i][1] % x[i][0] == 0 and (not(x[i][1] in ansList)) :
            count += 1
            ansList.append(x[i][1])

    print(n - count - num)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from numba import njit, int32, int64
from numba.typed import Dict

@njit
def solve(B):
    A = Dict.empty(
        key_type=int64,
        value_type=int64)
    for b in B:
      A[b] = A.get(b, 0) + 1
    r = 0
    if 1 in A:
        if A[1] == 1:
            return 1
        return 0
    for a, v in A.items():
        if v > 1:
            continue
        i = 2
        while i * i <= a:
            if a % i == 0:
                if i in A:
                    break
                if a // i in A:
                    break
            i += 1
        else:
            r += 1
    return r

def main():
    N = int(input())
    A = list(map(int, input().split()))
    return solve(A)

print(main())

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = list(map(int, input().split()))
count = [0]*N
nums.sort()
answer = N
for i in range(N):
  fNum = nums[i]
  for j in range(N):
    sNum = nums[j]
    if (sNum > fNum):
      break
    elif (i == j):
      continue
    else:
      if (fNum%sNum == 0):
        answer -= 1
        break

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
cnt = 0
for i in range(n):
    for j in range(n):
        if i != j:
            if a[i] % a[j] == 0:
                cnt += 1
                break
print(n-cnt)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
li = list(map(int, input().split()))
ans = []
kotae = 0
for i in range(a):
    for j in range(a):
        if not i == j:
            if not li[i] % li[j] == 0:
                ans.append(i)
    if ans.count(i) == a-1:
        kotae += 1
print(kotae)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = set()
for i in range(1, n+1):
    check = 0

    for j in range(1, n+1):
        if i == j: pass
        else:
            if a[i-1] % a[j-1] != 0: pass
            else:
                check += 1

    if check == 0:
        ans.add(i)
                
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
 
n = int(input())
a = list(map(int, input().split()))
counter = set([])
for i in range(n - 1):
    a_np = np.roll(np.array(a), i + 1)
    index = np.where(a % a_np == 0)
    counter = counter | set(index[0])
print(n - len(counter))