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:
import sys


def Sieve(N, AList):
    AList.sort()
    N_NotDivisible = 0
    while( len(AList) > 0 ):
        if(len(AList) > 1):
            if(AList[0]!= AList[1]):
                N_NotDivisible+= 1
                value = AList[0]
                pops = [0]
                for i in range(1, len(AList)):
                    if(AList[i]%value==0):
                        pops.append(i)
                AList.pop(pops)
            else:
                index = 2
                while(index < len(AList) and AList[index-1] == AList[index]):
                    index += 1
                for i in range(index):
                    AList.pop(0)

        else:
            N_NotDivisible+= 1
            break
    #print(Mins)
    return N_NotDivisible

if(__name__ == "__main__"):

    N = int( input().strip() )
    AList_str = input().strip().split()

    AList = [0] * N
    for i in range(N):
        AList[i] = int(AList_str[i])
    N_NotDivisible= Sieve(N, AList)
    print(N_NotDivisible)

Submission status: Runtime Error

Solution code:
# D - Not Divisible

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


if a[0]==a[1]:
    b[0]=0
    b[0]=0

b = [1]*n
for i in range(n):
    for j in range(i):
        #print(i,j)
        #print(a[i], "%", a[j] )
        if a[i]==a[j]:
            b[i]=0
            b[j]=0
            break
        elif a[i]%a[j]==0:
            b[i]=0
            break

#---check
#print(b)

print(sum(b))

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
if(A[0]!=A[1]):
  p=[A[0]]
else:
  p=[]
#print(ikiteru)
lis=[]
for i in range(1,N):
  flag=True
  if(i<N-1):
    if(A[i+1]!=A[i]):
      ans+=1
  elif(A[i-1]!=A[i]):
    ans+=1
  for q in p:
    if(A[i]%q==0):
      flag=False
  if flag:
    p.append(A[i])
print(len(p))
#print(x)

Submission status: Runtime Error

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

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 histogram(data):
    table = []
    prev = data[0]
    c = 1 
    for i in range(1,len(data)):
        if prev == data[i]:
            c=c+1
        else:
            table.append([prev,c])
            prev = data[i]
            c = 1
    table.append([prev,c])
    return table

K = []
for i in range(N):
    B = make_divisors(A[i])
    B.sort()
    B.pop(-1)
    K.append(B)
    
K.sort()

L = histogram(K)

M = []
for i in range(L):
    M.append(L[i][0])
    
ans = 0    
for i in range(len(M)):
    s = 0
    for j in range(N):
        if M[i] == A[j]:
            s = s+1
    if s = 0:
        ans = ans + 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
a_list = list(map(int,input().split()))
def seachPrimeNum(n):
    sagasu = a_set
    max_ = a_set[-1]
    while sagasu[0]*2 <= max_:
        sosuu.append(sagasu[0])
        tmp = sagasu[0]
        sagasu = [i for i in sagasu if i % tmp != 0]
        if len(sagasu) == 0:
            break
        
    sosuu.extend(sagasu)
    return len(sosuu)

a_list.sort()
a_set = []
if a_list[0] != a_list[1]:
    a_set.append(a_list[0])
for i in range(len(a_list)-2):
    if a_list[i+1] != a_list[i]:
        if a_list[i+1] != a_list[i+2]:
            a_set.append(a_list[i+1])
if a_list[-1] != a_list[-2]:
    a_set.append(a_list[-1])



if a_list[0] == 1:
    print(1)
    quit()
if len(a_set) == 0:
    print(0)
    quit()

sosuu = []

print(seachPrimeNum(a_list[0]))

Submission status: Runtime Error

Solution code:
def iput(): return int(input())
def mput(): return map(int, input().split())
def lput(): return list(map(int, input().split()))

def solve():
    n = iput()
    a = lput()
    a.sort()
    ans = 0
    if a[0] == a[1]:
        ans += 1
    for i in range(1,n):
        for j in range(0, i):
            if a[i] % a[j] == 0:
                ans += 1
                break
    print(n - ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

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

import numpy as npz

ans = 0
for i in range(N):
    c = list(A[i]%np.array(A))
    if A.count(A[i]) == N:
        ans = 0
        break
        break
    if c.count(0) == 1:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted([i for i in a if a.count(i) == 1])
    a = np.array(a)
    ans = []
    if let(set(a)) == 1:
        print(0)
        return
    while a != []:
        ans.append(a[0])
        a = a[a%a[0] != 0]
    print(len(ans)+1)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    A = LI()

    A.sort()
    divisible = set(list(range(1, 10**6+1)))

    for i in A:
        j = 1
        while i*j <= 10**6:
            if i*j in divisible:
		        divisible.remove(i*j)
                j += 1

    ans = 0
    for i in A:
        if j in divisible:
            ans += 1
        
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
if 1 in a:
    print(0)
elif:
    for i in a:
        for j in a:
            if j % i == 0 and j != i:
                a.remove(j)
            if a.count(i) >= 2:
                for k in range(a.count(i)):
                    a.remove(i)

print(len(a))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = [0]*len(a)
cnt = len(a)
k = 1
for e in a:
  if c[i]==1:
    continue
  for i in range(len(a)):
    if a[i]%e!=0:
      continue
    else:
      c[i] = 1
      cnt -= 1
  k +=1
if c[1]==1 and a[0]!=0:
  print(0)
else:
  print(cnt)

Submission status: Runtime Error

Solution code:
import sympy
n = int(input())

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

a.sort(reverse = True)

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

if len(set(a)) == 1:
    print(0)
else:
    
    
    ans = 0

    for i in range(n):
        target = sympy.divisors(a[i])
        if len(set(target) & set(a)) == 1:
            ans += 1

    print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
"""AtCoder Beginner Contest 170: D - Not Divisible
https://atcoder.jp/contests/abc170/tasks/abc170_d
"""


cache = {}


def calc_primes(n):
    primes = [True] * (n + 1)
    primes[0] = False
    primes[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not primes[i]:
            continue
        for j in range(i * 2, n + 1, i):
            primes[j] = False
    return primes


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

    ans = set()
    primes = calc_primes(2 * 10**5)
    for i in range(N):
        if As[i] in cache:
            continue
        if As[i] == 1:
            cache[As[i]] = True
            ans.add(i + 1)
            continue
        if 2 <= As.count(As[i]):
            cache[As[i]] = True
            continue  # has some number
        if primes[As[i]]:
            cache[As[i]] = True
            ans.add(i + 1)
            continue

        is_divisible = False
        for j in range(N):
            if i != j and As[i] % As[j] == 0:
                is_divisible = True
                break
        if not is_divisible:
            ans.add(i + 1)

    print(len(ans))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

s = [a[0]]
for i in range(1, n):
  s.append(a[i] * s[i-1])

for i in range(n):
  if i == 0:
    if a[i] != a[i+1]:
      cnt += 1
    continue
  if i != n-1:
    if a[i] % s[i-1] != 0 and a[i+1] != a[i]:
    cnt += 1
  if i == n-1:
    if a[i] % s[i-1] != 0:
      cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
import bisect

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 index(a, x):
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    else:
        return -1

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

A = set(A)
A = list(A)
A.sort()

cnt = 0
print(A)
for a in A:
    numlist = make_divisors(a)
    div = 0
    for x in numlist:
        if index(A, x) != -1:
            div += 1
    if div != 1:
        cnt += 1
if cnt == 0:
  print 0
 else:
  print(len(A) - cnt)

Submission status: Runtime Error

Solution code:

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors[1:] + upper_divisors[::-1]

# print('input >>')
N = int(input())
As = list(map(int,(input().split())))

As.sort()
print(As)

warusu = set()
ans = 0

# for x in range(len(As)):
    # print(As)

for A1 in As:
    for A2 in sorted(As, reverse=True):
        if A2 % A1 == 0
            As.remove(A1)

# print('-----output-----')
print(len(As))

Submission status: Runtime Error

Solution code:
N=int(input())
P=list(map(int, input().split()))
P.sort()
if P[0]==P[N-1]:
    print(0)
else:
    sum1=0
    while len(P)>1:
        if P[0]==P[1]:
            P1=[x for x in P if x%P[0]==0]
            for x in P1:
                P.remove(x)
        if P[0]<P[1]:
            sum1+=1
            P1=[x for x in P if x%P[0]==0]
            for x in P1:
                P.remove(x)
    sum1+=1
    print(sum1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
ans = 0
if len(a) == 1:
    print(0)
else:
    for _ in range(n):
        m = a.pop()
        ind = True
        for i in a:
            if m % i == 0:
                ind = False
                break
        if ind:
            ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
*A, = map(int, input().split())
A.sort()
a = []
b = []
last = 0
for i in range(N):
    if last != A[i]:
        a.append([A[i], 0])
        b.append(A[i])
        last = A[i]
    a[-1][1] += 1


def factorList(n):
    # [素因数]=数を出力
    f = {}
    c = 0
    r = int(n**0.5)
    l = []
    for i in range(2, r+2):
        while n % i == 0:
            c += 1
            n = n//i
        if c != 0:
            l.append([i, c])
            c = 0
    if n != 1:
        l.append([n, 1])
    return l


def cmb(a, i, h, t):
    if i >= len(a):
        return h[t]
    for j in range(a[i][1]+1):
        d = cmb(a, i+1, h, t*pow(a[i][0], j))
        if d:
            return True
    return False


h = [False]*(10**6+1)
ans = 0
for n, c in a:
    if c == 1:
        f = {}
        cc = 0
        r = int(n**0.5)
        l = []
        nn = n
        for i in range(2, r+2):
            while nn % i == 0:
                cc += 1
                nn = nn//i
            if cc != 0:
                l.append([i, cc])
                cc = 0
        if n != 1:
            l.append([n, 1])

        if not cmb(l, 0, h, 1):
            ans += 1
    h[n] = True

print(ans)

Submission status: Runtime Error

Solution code:
import sys,collections
input=sys.stdin.readline
n=int(input())
l=list(map(int,input().split()))
c=collections.Counter(l)
x=list(set(l))
x.sort()
ans=0
s=set()
for y in x: 
    if c[y]<2:
      memo=0
      for j in range(1,int(y**0.5)+1):
        if y%j == 0 :
          if y//j in s or j in s:
            memo-=1
            break
      if memo==0:
        ans+=1     
    s.add(y)
  print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

arr=np.array(lis, float)
arro=np.outer(arr,1/arr)
#print(tf)
#print(np.sum(tf, axis=1))

print(sum(np.sum(arro==arro.astype(np.int32), axis=1)==1))

Submission status: Runtime Error

Solution code:
import math
import sys
n=int(input())
a=list(map(int,input().split()))
a.sort()
M=max(a)
p=[]

for i in range(n):
    p.append([j for j in range(a[i],M+1,a[i])])
print(len(set(set(a)-set(p))))

Submission status: Runtime Error

Solution code:
import sys
import copy
from collections import deque
stdin = sys.stdin
 
mod = 10**9+7
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n = ni()
a = na()
a.sort()
b = copy.deepcopy(a)
 
maps = {}
 
for aa in a:
    if aa in maps:
        tmp = maps[aa]
        maps[aa] = tmp+1
    else:
        maps[aa] = 1
 
i = 0
while True:
    a_tmp = b[i]
    check = set()
    for j in range(len(b)-1, i, -1):
        if b[j]==a_tmp:
            check.add(i)
            check.add(j)
            continue
        if b[j]%a_tmp==0:
            check.add(j)
            continue
        if a_tmp*2 > b[j]:
            break
 
    check = list(check)
    check.sort(reverse=True)
    for c in check:
        del b[c]
    
    i += 1
    if i>=len(a):
        break
 
 
 
print(len(a))

Submission status: Runtime Error

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


def main():
    n = int(input())
    A = [int(i) for i in input().split()]
    ans = 1
    A.sort()
    A = dq(A)

    print(type(A))

    while A:
        start = A.popleft()
        if not A:
            break
        ans += 1
        A = dq([a for a in A if a % start != 0])

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
mis=0
if a[1]!=a[2]:
  ans+=1
for i in range(1,len(a)):
  if a[i]==a[i-1]:
    continue
  for j in range(min(len(a),i+2)):
    if a[i]%a[j]==0:
      if i!=j:
        mis=1
        break
  if mis==0:
    ans+=1
  mis=0
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

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

rcnt=0
length=len(A)
def length(n,*A):
    
    for i in range(length):
        if A[i]==A[i+1]:
            cnt+=1
        if cnt==N:
            print(0)
            return

    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)
length(*A)

Submission status: Runtime Error

Solution code:
import math
n = map(int,input())
a = list(map(int,input().split()))
P = []
for t in range(n):
  p = min(a)
  P.append(p)
  a.remove(p)
  i = 0
  while i < len(a):
    if a[i] % p == 0 and a[i] != p:
      a.pop[i]
      continue
    i += 1
print(len(P))

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 0
    if a[0] != a[1]:
        ans += 1

    for i in range(1, n):
        flg = True
        if i != n - 1:
            if a[i] == a[i - 1] or a[i] == a[i + 1] or a[i] < a[i-1]*2:
                continue
        else:
            if a[i] == a[i - 1] or a[i] < a[i-1]*2:
                continue

        for j in range(i):
            if a[i] % a[j] == 0:
                flg = False
                break
            if a[j] * 2 > a[i]:
                break
        if flg:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

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

sosu = []
count = 0

def loop(target, A):
  global count
  B = []
  flg = True
  for i in range(len(A)):
    if A[i] % target != 0:
      B.append(A[i])
    if target == A[i]:
      flg = False
  if flg:
    count+=1
  if len(B) == 1:
    count+=1
    return
  target = B.pop(0)
  loop(target, B)

target = A.pop(0)
loop(target, A)
print(count)

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
A = sorted([ int(i) for i in input().strip().split(' ')])
n = [ i for i in range(N) ]
B = [0] * N

for i in n:
    for j in copy.copy(n):
        if i == j:
            continue
        if A[i] == A[j]:
            B[i] = 1
            B[j] = 1
            n.remove(i)
            n.remove(j)
        elif A[j] % A[i] == 0:
            B[j] = 1
            n.remove(j)

print(N - sum(B))

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])
            num += 1
            continue
    for j in l:
        if a[i]%j:
            flag = 1
            break
        else:
            break
    if flag:
        l.append(a[i])
        num += 1

print(num)

Submission status: Runtime Error

Solution code:
N=int(input())
A= list(map(int,input().split()))
c=0
ans=0
for i in range (N):
  a=1
  
  if not(A[c]/A[c+a]==A[c]%A[c+a]):
    
    ans=ans+1
  f=-1
  if not(A[c]/A[c+a]==A[c]%A[c+f]):
    ans=ans+1
  f=f-1
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def Sieve(N, AList):
    AList.sort()
    N_NotDivisible = 0
    while( len(AList) > 0 ):
        if(len(AList) > 1):
            if(AList[0]!= AList[1]):
                N_NotDivisible+= 1
                value = AList[0]
                pops = [0]
                for i in range(1, N):
                    if(AList[i]%value==0):
                        pops.append(i)
                AList.pop(pops)
            else:
                index = 2
                while(index < len(AList) and AList[index-1] == AList[index]):
                    index += 1
                for i in range(index):
                    AList.pop(0)

        else:
            N_NotDivisible+= 1
            break
    #print(Mins)
    return N_NotDivisible

if(__name__ == "__main__"):

    N = int( input().strip() )
    AList_str = input().strip().split()

    AList = [0] * N
    for i in range(N):
        AList[i] = int(AList_str[i])
    N_NotDivisible= Sieve(N, AList)
    print(N_NotDivisible)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
i = 0
while True:
    x = A[i]
    u = 0
    flag = True
    for j in range(i+1,N):
        j -= u
        if x == A[j]:
            flag = False
        if A[j]%x == 0:
            A.pop(j)
            N -= 1
            u += 1
        if j == N-1:
            break
    if flag == False:
        A.pop(i)
        N -= 1
        u += 1
    if i == N-1:
        break
    i += 1
print(len(A))

Submission status: Runtime Error

Solution code:
import copy


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

a.sort()

arrs = []

for j in a:
	arr = []
	temp = j
	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])

	arrs.append(arr)

mf = []
mfe = []
ans = 0

for i in range(n):
	if i == 0:
		mfp = []
		mfep = []
	else:
		mfp = copy.deepcopy(mf[i-1])
		mfep = copy.deepcopy(mfe[i-1])
	t = 0
	for j in arrs[i]:
		if j[0] in mfp:
			k = mfp.index(j[0])
			if j[1] >= mfep[k]:
				mfep[k] = j[1]
				t += 1
		else:
			mfp.append(j[0])
			mfep.append(j[1])
			t += 1
	if i>0:
		for m in mfe[i-1]:
			if mfe[mfe[i-1].index(m)]<m:
				break
		else:
			ans+=1
	
	mf.append(mfp)
	mfe.append(mfep)

print(ans+1)

Submission status: Runtime Error

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

d_num = a

div = []
a_set = list(set(a))
flag = false
if len(a_set) == 1:
    print(0)
else:
    for i in range(len(a_set)):
        flag = false
        # for j in range(len(div)):
        #     if(a_set[i]%div[j] == 0):
        #         d_num -= 1
        #         flag = true
        #         break
        if flag == False:
            div.append(a_set[i])
    print(1)

Submission status: Runtime Error

Solution code:
n=int(input())
A=sorted(map(int,input().split()))
L=[A[0]]
if n==0:
    print(0)
else:
    c=0
    if A[0]!=A[1]:
        c=1
    for i in range(n-1):
        flag=0
        for l in L:
            if A[i+1]%l==0:
                flag=1
                break
            if l>=int(A[i+1]**0.5+1):
                break
        if flag==0:
            L.append(A[i+1])
            c+=1
    print(c)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
A.sort()


ans = 0
for i in range(N):
    if D[A[i]] == 1:
        flag=True
        cnt=0
        for j in range(i):
            if A[i] % A[j] == 0:
                cnt+=1

            if A[j]**2 > A[i]:
                break
        if cnt==1:
            ans += 1
    else:
        pass
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
ans = 0
if len(a) == 1:
    print(0)
else:
    for _ in range(n):
        m = a.pop()
        ind = True
        print(a)
        for i in a:
            if m % i == 0:
                ind = False
                break
        if ind:
            ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
#Q4
input()
nums = [int(s) for s in input().split(" ")]
nums.sort(reverse=True)
count = 0

for i in range(len(nums) - 1):
    flag = 0
    for j in range(1, len(nums) - i):
        if(nums[i] == nums[i - 1]):
            flag = 1
        #print("{0} % {1} = {2}".format(nums[i], nums[i + j], nums[i]%nums[i + j]))
        if nums[i]%nums[i + j] == 0:
            flag = 1
    if flag == 0:
        count = count + 1
if(nums[-1] == nums[-2]):
    print(count)
else:
    print(count + 1)

Submission status: Runtime Error

Solution code:
from collections import deque
import collections
n = int(input())
a = list(map(int,input().split()))
a.sort()
# print(a)
a = deque(a)
 
# b = a[-1]
# print(b)
# c = 0
while a[0]!=max(a) :
    p = a.popleft()
    x = []
    for i in a:
        if not i in x:
            # print(i,p)
            if i%p==0 and i!=p:
                # print(i)
                x.append(i)
    for j in x:
         a.remove(j) 
    a.append(p)
y=len(a)
# print(a)
c = (collections.Counter(a)).values()
# print(c)
for i in c:
    # print(i)
    if i!=1:
        y-=i
    # c+=1
    # if a[i]<b/2:
    #     a =a[:i+1]+ [k for k in a if k%a[i]!=0]
print(y)
from collections import deque
import collections
n = int(input())
a = list(map(int,input().split()))
a.sort()
# print(a)
a = deque(a)

b = a[0]
# print(b)
c = 0
while not(a[0]==b and c==1) :
    p = a.popleft()
    x = []
    for i in a:
        if not i in x:
            # print(i,p)
            if i%p==0 and i!=p:
                # print(i)
                x.append(i)
    for j in x:
         a.remove(j) 
    a.append(p)
    c=1
y=len(a)
# print(a)
c = (collections.Counter(a)).values()
# print(c)
for i in c:
    # print(i)
    if i!=1:
        y-=i
    # c+=1
    # if a[i]<b/2:
    #     a =a[:i+1]+ [k for k in a if k%a[i]!=0]
print(y)

Submission status: Runtime Error

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

count = 0
B = [0] * (10**6)

for i in range(N):
    B[A[i]] = 1

for i in range(N):
    flag = 1
    X = A[i]
    for j in range(1,int(X**0.5)+1):
        if X % j == 0:
            if B[j] == 1:
                flag = 0
            if (j != X // j) and (j != 1):
                if B[X//j] == 1:
                    flag = 0
    if i != N-1:
        if X == A[i+1]:
            flag = 0
    if i != 0:
        if X == A[i-1]:
            flag = 0

    if flag == 1:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
#import numpy as np
import sympy as sp
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

num = defaultdict(int)
ans = defaultdict(int)
for i, a in enu(A):
    if num[a] > 0:
        num[a] += 1
        continue

    divs = sp.divisors(a)
    # print('divs', divs)
    for div in divs:
        if num[div] > 0:
            break
    else:
        ans[a] += 1
    num[a] += 1

cnt = 0 
# print(num)
# print(ans)
for an in ans.items():
    k, v = an
    if num[k]==1:
        cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
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.extend([i for _ in range(cnt)])

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

    if arr==[]:
        arr.extend([n])

    return arr

class Node:
  def __init__(self, data, num, flag):
    self.data = data
    self.next = []
    self.num = num
    self.flag = flag
  def add_next(self, data, flag):
    self.next.append(Node(data, self.num+1, flag))
    
  def search(self, data):
    for i in range(len(self.next)):
      if(self.next[i].data == data):
        return i
    return -1
      
def set_tree(tree, ss, ind):
  kk = tree.search(ss[ind])
  if(kk != -1):
    if(tree.next[kk].flag):
      return False
    if(ind == len(ss)-1):
      return False
    else:
      return set_tree(tree.next[kk], ss, ind+1)
      
  else:
    if(ind == len(ss)-1):
      tree.add_next(ss[ind], True)
      return True
    else:
      tree.add_next(ss[ind], False)
      return set_tree(tree.next[-1], ss, ind+1)
    
    
      
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [a[0]]
for i in a[1:]:
  if (b[-1] == i):
    continue
  else:
    b.append(i)
a= b

if(1 in a):
  print(0)
  exit()

s = []
for i in range(n):
  s.append(factorization(a[i]))


tree = Node(1, 0, False)
count = 0

for i in range(n):
  if(set_tree(tree, s[i], 0)):
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

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

arr=np.array(lis, float)
arro=np.outer(arr,1/arr)
tf= arro==arro.astype(np.int32)
#print(tf)
#print(np.sum(tf, axis=1))

print(sum(np.sum(tf, axis=1)==1))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
if len(a)==l.count(l[0]):
  print(0)
else :
  count = 0
  for i in range(1,n):
    if l[i]==l[i+1] or l[i]==l[i-1]:
      continue
    for j in range(i):
      if math.sqrt(l[i]) < l[j]:
        break
      if l[i] % l[j]:
        break
    else :
      count += 1
  print(count)

Submission status: Runtime Error

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    from sympy import sieve
    import sys
    import math
    import copy
    input=sys.stdin.readline
    n=I()
    a=L()
    
    primelist=[i for i in sieve.primerange(1,int(math.sqrt(1e+6))+1)]
    
    dic={}
    for i in range(n):
        for j in primelist:
            if a[i]%j==0:
                if j in dic:
                    dic[j].add(a[i])
                else:
                    dic[j]={a[i]}
    ans=0
    a=list(set(a))
    keyset=set([i for i in dic.keys()])
    if len(a)==1:
        print(0)
        exit()
    for i in range(len(a)):
        tmpset=copy.copy(keyset)
        seta=set(a)
        tmp=[]
        for j in primelist:
            if a[i]%j==0:tmp.append(j)
        tmpset=tmpset - set(tmp)
        for j in tmpset:
            seta=seta-dic[j]
        ans+=1 if(min(seta)==a[i]) else 0 
    print(ans)
    
if __name__ == '__main__':
    main()