input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(readline()) a = list(map(int,readline().split())) a.sort() if a[0] == a[-1]: if n > 1: print((0)) else: print((1)) exit() def gcd(a, b): while b: a, b = b, a ...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(readline()) a = list(map(int,readline().split())) a.sort() if a[0] == a[-1]: if n > 1: print((0)) else: print((1)) exit() def gcd(a, b): while b: a, b = b, a ...
p02642
from collections import Counter N = int(eval(input())) A = sorted(map(int, input().split()), reverse=False) m = max(A)+1 dp = [True] * m for x in list(set(A)): t = x * 2 while t < m: dp[t] = False t += x ans = 0 for a in A: if Counter(A)[a] == 1 and dp[a]: ans += 1 prin...
from collections import Counter N = int(eval(input())) A = sorted(map(int, input().split()), reverse=False) m = max(A)+1 c = Counter(A) s = list(set(A)) dp = [True] * m for x in s: t = x * 2 while t < m: dp[t] = False t += x ans = 0 for a in A: if c[a] == 1 and dp[a]: ...
p02642
from collections import Counter N = int(eval(input())) A = sorted(map(int, input().split()), reverse=False) m = max(A)+1 s = list(set(A)) dp = [True] * m for x in s: t = x * 2 while t < m: dp[t] = False t += x ans = 0 for a in A: if Counter(A)[a] == 1 and dp[a]: ans += ...
from collections import Counter N = int(eval(input())) A = sorted(map(int, input().split()), reverse=False) m = max(A)+1 c = Counter(A) s = list(set(A)) dp = [True] * m for x in list(set(A)): t = x * 2 while t < m: dp[t] = False t += x ans = 0 for a in A: if c[a] == 1 and dp[a]...
p02642
from bisect import bisect_left, bisect_right n = int(eval(input())) a = list(map(int, input().split())) a.sort() m = a[-1] c = [0] * (m + 1) for ai in a: for i in range(ai, m + 1, ai): if bisect_right(a, i) - bisect_left(a, i) == 1: c[i] += 1 print((c.count(1)))
n = int(eval(input())) a = list(map(int, input().split())) a.sort() m = a[-1] c = [0] * (m + 1) for ai in a: for i in range(ai, m + 1, ai): c[i] += 1 ans = 0 for ai in a: if c[ai] == 1: ans += c[ai] print(ans)
p02642
from collections import defaultdict def resolve(): N = int(eval(input())) A = list(map(int, input().split())) a_max = max(A)+1 B = defaultdict(int) for i in range(N): a = A[i] if B[a]>1: B[a] = 2 else: for j in range(a, a_max, a): B[j] += 1 Y = 0 for a in A: if B[a]==1: Y+=...
def resolve(): N = int(eval(input())) A = list(map(int, input().split())) a_max = max(A)+1 B = {} for i in range(N): a = A[i] if a not in list(B.keys()): for j in range(a, a_max, a): B[j] = False B[a] = True else: B[a] = False Y = list(B.values()).count(True) print(Y) resolve()
p02642
n = int(eval(input())) a = [int(i) for i in input().split()] table = [True for _ in range(10 ** 7)] a.sort() ans = 0 for i in range(n): if table[a[i]]: for j in range(a[i], 10 ** 7, a[i]): table[j] = False if i + 1 < n: if a[i + 1] != a[i]: ans += 1...
n = int(eval(input())) a = [int(i) for i in input().split()] table = [True for _ in range(2 * (10 ** 6))] a.sort() ans = 0 for i in range(n): if table[a[i]]: for j in range(a[i], 2 * (10 ** 6), a[i]): table[j] = False if i + 1 < n: if a[i + 1] != a[i]: ...
p02642
n = int(eval(input())) a = [int(i) for i in input().split()] table = [True for _ in range(2 * (10 ** 6))] a.sort() ans = 0 for i in range(n): if table[a[i]]: for j in range(a[i], 2 * (10 ** 6), a[i]): table[j] = False if i + 1 < n: if a[i + 1] != a[i]: ...
T = 10 ** 6 + 20 n = int(eval(input())) a = [int(i) for i in input().split()] table = [True for _ in range(T)] a.sort() ans = 0 for i in range(n): if table[a[i]]: for j in range(a[i], T, a[i]): table[j] = False if i + 1 < n: if a[i + 1] != a[i]: an...
p02642
n = int(eval(input())) l = [int(x) for x in input().split()] l.sort() set_l = set(l) set_l = sorted(set_l) limit = 10**6 mp = [0]*(limit+1) pre = None for i in range(n): num = l[i] if(pre==num): mp[num] += 1 pre = num for x in set_l: num = x while(x <= limit): mp[x]...
n = int(eval(input())) l = [int(x) for x in input().split()] l.sort() set_l = set(l) set_l = sorted(set_l) limit = 10**6+1 mp = [0]*(limit) pre = None for i in range(n): num = l[i] if(pre==num): mp[num] += 1 pre = num for x in set_l: for y in range(x,limit,x): mp[y] += 1...
p02642
n = int(eval(input())) l = [int(x) for x in input().split()] l.sort() set_l = set(l) set_l = sorted(set_l) limit = 10**6+1 mp = [0]*(limit) pre = None for i in range(n): num = l[i] if(pre==num): mp[num] += 1 pre = num for x in set_l: for y in range(x,limit,x): mp[y] += 1...
n = int(eval(input())) l = [int(x) for x in input().split()] D = set() #Duplication S = set() #all for x in l: if x in S: D.add(x) else: S.add(x) limit = 10**6+1 mp = [0]*(limit) cnt = 0 S = sorted(S) for x in S: for y in range(x,limit,x): mp[y] += 1 if(x in D...
p02642
n = int(eval(input())) l = [int(x) for x in input().split()] D = set() #Duplication S = set() #all for x in l: if x in S: D.add(x) else: S.add(x) limit = 10**6+1 mp = [0]*(limit) cnt = 0 S = sorted(S) for x in S: for y in range(x,limit,x): mp[y] += 1 if(x in D...
n = int(eval(input())) l = [int(x) for x in input().split()] D = set() #Duplication S = set() #all for x in l: if x in S: D.add(x) else: S.add(x) M = max(S) limit = M+1 mp = [0]*(limit) cnt = 0 S = sorted(S) for x in S: for y in range(x,limit,x): mp[y] += 1 i...
p02642
from collections import Counter n=int(eval(input())) a=list(map(int,input().split())) a.sort() is_p=[1 for i in range(10**6+1)] for i in range(n): v=a[i] if is_p[v]: for j in range(v+v,10**6+1,v): # print(j) is_p[j]=0 c=Counter(a) cnt=0 for i in a: if is_p[i]==1 and c[i]==1:...
from collections import Counter n=int(eval(input())) a=list(map(int,input().split())) a.sort() is_p=[1 for i in range(10**6+1)] for i in set(a): v=i if is_p[v]: for j in range(v+v,10**6+1,v): is_p[j]=0 c=Counter(a) cnt=0 for i in a: if is_p[i]==1 and c[i]==1: cnt+=1 print(...
p02642
from collections import Counter n=int(eval(input())) a=list(map(int,input().split())) is_p=[1]*(10**6+1) for i in a: if is_p[i]: for j in range(i+i,10**6+1,i): is_p[j]=0 c=Counter(a) cnt=0 for i in a: if is_p[i] and c[i]==1: cnt+=1 print(cnt)
from collections import Counter n=int(eval(input())) a=list(map(int,input().split())) is_p=[1]*(10**6+1) for i in set(a): if is_p[i]: for j in range(i+i,10**6+1,i): is_p[j]=0 c=Counter(a) cnt=0 for i in a: if is_p[i] and c[i]==1: cnt+=1 print(cnt)
p02642
from collections import Counter n=int(eval(input())) a=list(map(int,input().split())) c=Counter(a) def eratosthenes(lim): is_p=[1]*lim is_p[0]=1 is_p[1]=1 for i in a: if is_p[i]: for j in range(i*2,lim,i): is_p[j]=0 return is_p lim=10**6+5 is_p=eratosthenes(lim) ...
from collections import Counter n=int(eval(input())) a=list(map(int,input().split())) c=Counter(a) def eratosthenes(lim): is_p=[1]*lim is_p[0]=1 is_p[1]=1 for i in set(a): if is_p[i]: for j in range(i*2,lim,i): is_p[j]=0 return is_p lim=10**6+5 is_p=eratosthenes(lim...
p02642
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) from collections import Counter n=int(eval(input())) l=lnii() def eratosthenes(lim): num=[1 for i in range(lim)] for i in l: for j in range(i+i,lim,i): num[j]=0 ret...
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) from collections import Counter n=int(eval(input())) l=lnii() def eratosthenes(lim): num=[1 for i in range(lim)] for i in set(l): for j in range(i+i,lim,i): num[j]=0 ...
p02642
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) from collections import Counter n=int(eval(input())) l=lnii() def eratosthenes(lim): num=[1 for i in range(lim)] for i in set(l): for j in range(i+i,lim,i): num[j]=0 ...
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) from collections import Counter n=int(eval(input())) l=lnii() def eratosthenes(lim): num=[1 for i in range(lim)] for i in set(l): if num[i]: for j in range(i+i,lim,i):...
p02642
_,*a = list(map(int, open(0).read().split())) a.sort() m = -~a[-1] c = [0]*m for i in a: c[i] += 1 if c[i] > 1: continue for j in range(i * 2, m, i): c[j] = 2 print((sum(c[i]==1for i in a)))
#!/usr/bin/env python3 _, *a = list(map(int, open(0).read().split())) a.sort() p = [0] * a[-1] for i in a: for j in range(1, a[-1] // i + 1): p[j * i - 1] += j print((sum(i == 1 for i in p)))
p02642
import sys (n) = list(map(int, sys.stdin.readline().strip().split())) list_input = list(map(int, input().split())) # 1の数をカウント counts_one = list_input.count(1) if counts_one == 1: print(counts_one) sys.exit() elif counts_one > 1: print((0)) sys.exit() # 全て同じ数字かチェック counts_same = list_in...
import sys n = int(eval(input())) list_input = list(map(int, sys.stdin.readline().split())) list_input.sort() # 倍数判断用のリストを作成 list_div = [0]*(max(list_input)) for i in list_input: # print(i) a = list_div[i-1] # list_div[i-1::i] = [1]*(len(list_div[i-1::i])) list_div[i-1::i] = [x+1 for x...
p02642
from sys import stdin readline = stdin.readline def i_input(): return int(readline().rstrip()) def i_map(): return list(map(int, readline().rstrip().split())) def i_list(): return list(i_map()) def main(): N = i_input() A = i_list() ans = 0 for i, a in enumerate(A): for ii, aa in e...
from sys import stdin readline = stdin.readline def i_input(): return int(readline().rstrip()) def i_map(): return list(map(int, readline().rstrip().split())) def i_list(): return list(i_map()) def make_divisors(n): result = [] for i in range(1, int(n ** 0.5) + 1): if n % i == 0: ...
p02642
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(x) for x in input().split()] A.sort() ans = [0] * (10 ** 6 + 1) for a in A: for i in range(1, 10 ** 6 + 1): if a * i > 10 ** 6: ...
import sys import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(x) for x in input().split()] aset = list(set(A)) aset.sort() ans = [0] * (10 ** 6 + 1) for a in aset: for i in range(2, 10 ** 6 + 1):...
p02642
import sys import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(x) for x in input().split()] aset = list(set(A)) aset.sort() ans = [0] * (10 ** 6 + 1) for a in aset: for i in range(2, 10 ** 6 + 1):...
import sys import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(x) for x in input().split()] aset = list(set(A)) memo = [0] * (10 ** 6 + 1) for a in aset: for i in range(2, 10 ** 6 + 1): if...
p02642
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(x) for x in input().split()] A.sort() B = [0] * (max(A) + 1) ans = 0 for i, a in enumerate(A): if B[a] == 1: continue for aa in r...
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(x) for x in input().split()] A.sort() B = [0] * (A[-1] + 1) ans = 0 for i, a in enumerate(A): if B[a] == 1: continue for aa in ra...
p02642
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(x) for x in input().split()] A.sort() ma = A[-1] B = [False] * (ma + 1) ans = 0 for i, a in enumerate(A): if B[a]: continue ...
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N = int(eval(input())) A = [int(x) for x in input().split()] A.sort() ma = A[-1] B = [0] * (ma + 1) ans = 0 prev = 0 for a in A: if B[a] == 1: if prev == a: ...
p02642
from collections import Counter n = int(eval(input())) a = sorted([int(x) for x in input().split()]) freq = Counter(a) A = max(a) good = [True]*(A+1) ans = 0 for x in freq: for k in range(2*x,A+1,x): good[k] = False if good[x] and freq[x]==1: ans += 1 print(ans)
N = int(eval(input())) lineup = sorted([int(x) for x in input().split()]) duplicate={} for i in lineup: if i in duplicate: duplicate[i]+=1 else: duplicate[i]=1 b=max(lineup)+1 sieve=[1]*(b) counter=0 for i in range(N): if sieve[lineup[i]]: if duplicate[lineup[i]]==1: ...
p02642
N = int(eval(input())) A = sorted((list(map(int,input().split())))) a_Max = A[-1] B = [0]*a_Max for a in A: if B[a-1] == 0: B[a-1] = 1 for j in range(2,a_Max+1): if a*j > a_Max: break B[a*j-1] = 2 elif B[a-1] == 1: B[a-1] = 2 ...
N = int(eval(input())) A = sorted((list(map(int,input().split())))) a_Max = A[-1] B = [0]*a_Max ans =0 for a in A: if B[a-1] == 0: B[a-1] = 1 ans += 1 for j in range(a*2-1,a_Max,a): B[j] = 2 elif B[a-1] == 1: B[a-1] = 2 ans -= 1 print(ans)
p02642
n = int(eval(input())) a = list(map(int, input().split())) a_dic = {} for i in a: if not i in a_dic: a_dic[i] = 0 a_dic[i] += 1 res = 0 for i in a: j = 1 flag = 1 while j * j <= i: if i % j == 0: x = j if (x == i and a_dic[x] >= 2) or (x != i a...
n = int(eval(input())) a = list(map(int, input().split())) a.sort() bai = [0 for _ in range(max(a)+1)] i = 2 for i in a: j = i while j < len(bai): bai[j] += 1 j += i res = 0 if n <= 1: print(n) exit() for i in range(n): if i == 0: if a[i] != a[i+1] and bai...
p02642
def eratosthenes(a): data = [i for i in a] for d in data: data = [x for x in data if (x == d or x % d != 0)] return data n=int(eval(input())) a=list(map(int, input().split())) a.sort() L=eratosthenes(a) from collections import Counter c=Counter(L) ans=0 for v in list(c.values()): ...
from collections import Counter n=int(eval(input())) a=list(map(int, input().split())) a.sort() m=a[-1]+1 dp=[True]*m c=Counter(a) ans=0 for x in a: if dp[x] and c[x]==1: ans+=1 for j in range(2*x, m, x): dp[j]=False print(ans)
p02642
def resolve(): N = int(eval(input())) A = sorted(list(map(int, input().split()))) import collections counter = collections.Counter(A) dp = [True for _ in range(max(A)+1)] for a in A: if counter[a] > 1: dp[a] = False for j in range(a+a, max(A)+1, a): ...
def resolve(): N = int(eval(input())) A = sorted(list(map(int, input().split()))) import collections counter = collections.Counter(A) maxA = max(A) dp = [True for _ in range(max(A)+1)] for a in A: if counter[a] > 1: dp[a] = False for j in range(a+a, maxA...
p02642
import sys def input(): return sys.stdin.readline().strip() def main(): N = int(eval(input())) A = sorted(list(map(int,input().split()))) check = [0] * N ans = 0 for i in range(N): if check[i] == 1: continue elif check[i] == 0 and A.count(A[i]) == 1...
import sys def input(): return sys.stdin.readline().strip() def main(): N = int(eval(input())) A = sorted(list(map(int,input().split()))) A_max = A[-1] + 1 dp = [0] * A_max for i in A: dp[i] += 1 if dp[i] == 1: for j in range(i*2,A_max,i): ...
p02642
N=int(eval(input())) ls=list(map(int,input().split())) ls.sort() #定数倍のやつに+1する A=[0]*(max(ls)+1) for i in range(len(ls)): a=1 while ls[i]*a<=max(ls): b=ls[i]*a if A[b]<=1: A[b]+=1 a+=1 ans=0 for i in range(len(ls)): if A[ls[i]]==1: ans+=1 print(ans)
N=int(eval(input())) ls=list(map(int,input().split())) ls.sort() #定数倍のやつに+1する M=max(ls) A=[0]*(M+1) for i in range(N): a=M//ls[i] for j in range(1,a+1): if A[j*ls[i]]<=2: A[j*ls[i]]+=1 ans=0 for i in range(len(ls)): if A[ls[i]]==1: ans+=1 print(ans)
p02642
N=int(eval(input())) ls=list(map(int,input().split())) ls.sort() #定数倍のやつに+1する M=max(ls) A=[0]*(M+1) for i in range(N): a=M//ls[i] for j in range(1,a+1): A[j*ls[i]]+=1 ans=0 for i in range(len(ls)): if A[ls[i]]==1: ans+=1 print(ans)
N=int(eval(input())) ls=list(map(int,input().split())) ls.sort() #定数倍のやつに+1する M=max(ls) A=[0]*(M+1) for i in range(N): a=M//ls[i] for j in range(1,a+1): if A[ls[i]]>=2: break else: A[j*ls[i]]+=1 continue ans=0 for i in range(len(ls)): if A[ls[i]]==1: ans+=1 pri...
p02642
N = int(eval(input())) List = list(map(int, input().split())) res = 0 List.sort() K = List[N-1]+1 Flag = [1]*K for i in List: if Flag[i] ==1: res +=1 for j in range(i,K,i): Flag[j] = 0 if List.count(i) > 1: res += -1 print(res)
N = int(eval(input())) List = list(map(int, input().split())) res = 0 List.sort() K = List[N-1]+1 Flag = [1]*K for i in range(N): if Flag[List[i]] ==1: res +=1 for j in range(List[i],K,List[i]): Flag[j] = 0 if i != N-1 and List[i] == List[i+1]: res += -1 print(res)
p02642
n = int(eval(input())) a = list(map(int, input().split())) a.sort() flag = False b = [False] * 1000010 for i in range(n - 1): if a[i] == a[i + 1]: for j in range(a[i], 1000010, a[i]): b[j] = True ans = 0 for i in range(n): if not b[a[i]]: ans += 1 for j in rang...
n = int(eval(input())) a = list(map(int, input().split())) a.sort() flag = False b = [False] * 1000010 for i in range(n - 1): if a[i] == a[i + 1]: if b[a[i]]: continue for j in range(a[i], 1000010, a[i]): b[j] = True ans = 0 for i in range(n): if not b[a[i]...
p02642
n,*a=list(map(int,open(0).read().split())) ma=1001001 nums=[0]*ma for q in a: nums[q]+=1 if nums[q]==1: for j in range(2*q,ma,q): nums[j]+=2 cnt=0 for elem in nums: if elem==1: cnt+=1 print(cnt)
# coding: utf-8 # Your code here! def LI(): return list(map(int,input().split())) n=int(eval(input())) a=LI() a.sort() nums=[0]*(10**6+100) for q in a: if nums[q]==0: nums[q]=1 for j in range(2*q,10**6+1,q): nums[j]+=9 elif nums[q]==1: nums[q]+=9 ...
p02642
n = int(eval(input())) a=list(map(int,input().split())) a.sort() dp = [True for _ in range(a[n-1])] for val in set(a): for i in range(2*val,a[n-1]+1,val): dp[i-1]=False ans = 0 for val in a: if dp[val-1] and a.count(val)==1: ans+=1 print(ans)
n=int(eval(input())) a=list(map(int,input().split())) a.sort() dp=[True]*a[-1] def hantei(i): ans = True if i!=n-1: if a[i]==a[i+1]: ans = False if i!=0: if a[i]==a[i-1]: ans=False return ans for val in set(a): for i in range(2*val,a[-1]+1,val): dp[i-1]=False ans=0 for ...
p02642
n = int(eval(input())) a = list(map(int, input().split())) remain = [0 for i in range(max(a) + 1)] for ai in a: remain[ai] += 1 res = 0 for i in range(1, max(a) + 1): if remain[i] == 1: res += 1 if remain[i]: for j in range(i * 2, max(a) + 1, i): remain[j] = 0 print(r...
n = int(eval(input())) a = list(map(int, input().split())) remain = [0 for i in range(max(a) + 1)] for ai in a: remain[ai] += 1 res = 0 max_a = max(a) for i in range(1, max_a + 1): if remain[i] == 1: res += 1 if remain[i]: for j in range(i * 2, max_a + 1, i): remain[j...
p02642
INF=10**6+1 n,*l=list(map(int,open(0).read().split())) from collections import * c=Counter(l) l=sorted(c.keys()) a=[] b=[0]*INF for i in l: b[i]=1 for i in l: if b[i]: if c[i]<2: a+=[i] for j in range(2*i,INF,i): b[j]=0 print((len(a)))
M=10**6+1 _,*l=list(map(int,open(0).read().split())) b=[0]*M for i in l: b[i]+=1 a=[] for i in sorted(l): if b[i]: if b[i]==1: a+=[i] for j in range(i,M,i): b[j]=0 print((len(a)))
p02642
M=10**6+1 _,*l=list(map(int,open(0).read().split())) a=[0]*M for i in sorted(l): a[i]+=1 if a[i]==1: for j in range(2*i,M,i): a[j]+=9 print((a.count(1)))
M=10**6+1 _,*l=list(map(int,open(0).read().split())) a=[0]*M for i in sorted(l): if a[i]: a[i]=2; continue for j in range(i,M,i): a[j]+=1 print((sum(a[i]==1 for i in l)))
p02642
M=10**6+1 _,*l=list(map(int,open(0).read().split())) a=[0]*M for i in l: if a[i]<2: for j in range(i,M,i): a[j]+=2 a[i]-=1 print((a.count(1)))
M=10**6+1 _,*l=list(map(int,open(0).read().split())) a=[0]*M for i in l: if a[i]<1: for j in range(i*2,M,i): a[j]=2 a[i]+=1 print((a.count(1)))
p02642
def div(n): lower_div, upper_div = [], [] i = 1 while i * i <= n: if n % i == 0: lower_div.append(i) if i != n // i: upper_div.append(n // i) i += 1 return lower_div + upper_div[::-1] def main(): from collections import Counter ...
from collections import Counter n = int(eval(input())) A = sorted(map(int, input().split())) M = A[-1] c = Counter(A) s = set() ans = 0 for a in A: if a in s: continue if c[a] == 1: ans += 1 i = 1 while a * i <= M: s.add(a * i) i += 1 print(ans)
p02642
n = int(eval(input())) a = list(map(int, input().split())) aa = [0] * (10 ** 6 + 1) a.sort() ans = 0 for i in a: for j in range(i, 10 ** 6 + 1, i): aa[j] += 1 a = set(a) for k in a: if aa[k] == 1: ans += 1 print(ans)
n = int(eval(input())) a = list(map(int, input().split())) cnt = [0] * (10 ** 6 + 1) a.sort() ans = 0 for i in a: cnt[i] += 1 a = set(a) for k in a: for l in range(k * 2, (10 ** 6 + 1), k): cnt[l] += 1 for m in a: if cnt[m] == 1: ans += 1 print(ans)
p02642
n = int(eval(input())) a = list(map(int, input().split())) cnt = [0] * (10 ** 6 + 1) a.sort() ans = 0 for i in a: cnt[i] += 1 a = set(a) for k in a: for l in range(k * 2, (10 ** 6 + 1), k): cnt[l] += 1 for m in a: if cnt[m] == 1: ans += 1 print(ans)
n = int(eval(input())) a = list(map(int, input().split())) a.sort() max_num = a[-1] + 1 cnt = [0] * (max_num) a.sort() ans = 0 for i in a: cnt[i] += 1 a = set(a) for k in a: for l in range(k * 2, (max_num), k): cnt[l] += 1 for m in a: if cnt[m] == 1: ans += 1 ...
p02642
import sys input = sys.stdin.readline n = int(eval(input())) a = list(map(int, input().split())) a.sort() flg = [True for _ in range(10 ** 6 + 1)] for i in range(n-1): if a[i] == a[i+1]: flg[a[i]] = False ans = 0 for i in range(n): if flg[a[i]]: ans += 1 tmp = 1 while...
import sys input = sys.stdin.readline n = int(eval(input())) a = list(map(int, input().split())) a.sort() flg = [True for _ in range(10 ** 6 + 1)] for i in range(n-1): if a[i] == a[i+1]: flg[a[i]] = False ans = 0 for x in set(a): if flg[x]: ans += 1 tmp = 1 while tmp ...
p02642
import sys input = sys.stdin.readline N = int(eval(input())) a = list(map(int, input().split())) table = [0] * (max(a) + 1) for x in a: table[x] += 1 #print(table) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) ...
import sys input = sys.stdin.readline N = int(eval(input())) a = list(map(int, input().split())) mx = max(a) table = [0] * (mx + 1) for x in a: table[x] += 1 #print(table) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) ...
p02642
# D - Not Divisible from collections import Counter N = int(eval(input())) A = list(int(a) for a in input().split()) c = Counter(A) ng = set([i[0] for i in list(c.items()) if i[1] >= 2]) A.sort() M = max(A) primes = [] is_prime = [True] * (M+1) for i, a in enumerate(A): if is_prime[a]: if a ...
# D - Not Divisible N = int(eval(input())) A = list(int(a) for a in input().split()) A.sort() M = max(A) is_D = [0] * (M+1) for i, a in enumerate(A): if is_D[a]: is_D[a] = 2 continue for j in range(a, M+1, a): is_D[j] += 1 ans = 0 for a in A: if is_D[a] == 1: ...
p02642
N = int(eval(input())) arr = sorted(list(map(int, input().split()))) ans_list = [] chohuku = [x for x in set(arr) if arr.count(x) > 1] count_arr = [0]*arr[-1] ans = 0 for i in arr: if count_arr[i-1] == 0: ans += 1 ans_list.append(i) for j in range(1,(arr[-1]//i)+1): count_ar...
N = int(eval(input())) arr = sorted(list(map(int, input().split()))) count_arr = [0]*arr[-1] ans = 0 for i in arr: for j in range(1,(arr[-1]//i)+1): count_arr[(i*j)-1] += 1 for i in arr: if count_arr[i-1] == 1: ans +=1 print(ans)
p02642
n = int(eval(input())) a = list(map(int, input().split())) a_sorted = sorted(a) divisible_list = [True] * n for i in range(n-1): if not divisible_list[i]: continue for j in range(i+1, n): if a_sorted[j] == a_sorted[i]: divisible_list[i] = False tmp = j ...
n = int(eval(input())) a = list(map(int, input().split())) a_sorted = sorted(a) divisible_list = [0] * (max(a)+1) for i in range(len(a)): for j in range(0, len(divisible_list), a[i]): divisible_list[j] += 1 ans = 0 for i in range(len(a)): if divisible_list[a[i]] == 1: ans+=1 pri...
p02642
import sys N = int(eval(input())) argv = input().split() divisible = 0 count = 0 for i in range(N): divisible = 0 for j in range(N): if i == j: continue elif (int(argv[i]) % int(argv[j])) == 0: divisible = 1 break if divisible == 0: count += 1 pri...
N = int(eval(input())) intList = list(map(int, input().split())) intList.sort() cntList = [1] * (intList[-1] + 1) i = 0 j = 1 ans = 0 while i < (N - 1): base = intList[i] j = 1 num = base if cntList[num] == 1: while num <= intList[-1]: if cntList[num] == 1: cntList[num] =...
p02642
n = int(eval(input())) a = list(map(int, input().split())) b = set(i for i in range(n)) ans = [0]*n warizai_index = set() for i in range(n): for wari in warizai_index: if a[i]%a[wari] == 0 and i != wari: ans[i] = 1 if i in warizai_index: warizai_index.remo...
n = int(eval(input())) a = list(map(int, input().split())) a.sort() aMax = a[-1] ans = 0 dp = [1] * (aMax+1) for i in range(n-1): p = a[i] if dp[p] == 1: for j in range(aMax//p+1): dp[p*j] = 0 if a[i] != a[i+1]: ans += 1 if dp[aMax] == 1: ans += 1 pri...
p02642
from collections import Counter def is_divideable(a, nums): x = 1 while x ** 2 <= a: if a % x == 0: if x in nums or (a // x) in nums: return True x += 1 return False def main(): N = int(eval(input())) A = list(map(int, input().split())) ...
from collections import Counter def main(): N = int(eval(input())) A = list(map(int, input().split())) MAX = max(A) dp = [True] * (MAX+1) A.sort() cnt = Counter(A) ans = 0 for a in A: if dp[a]: if cnt[a] == 1: ans += 1 x = ...
p02642
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] #from fractions import gcd #from itertools import combinations # (string,3) 3回 #from collections import deque from collections import deque,defaultdict #import bisect # # d =...
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] #from fractions import gcd #from itertools import combinations # (string,3) 3回 #from collections import deque from collections import deque,defaultdict #import bisect # # d =...
p02642
n = int(eval(input())) a = list(map(int, input().split())) a.sort() flag = [True] * n for i in range(n): if not flag[i]: continue for j in range(i + 1, n): if a[j] % a[i] == 0: flag[j] = False if a[i] == a[j]: flag[i] = False print((flag.count(True)))
n = int(eval(input())) a = list(map(int, input().split())) a.sort() flag = [True] * (a[-1] + 1) memo = -1 for i in a: if memo == i: flag[i] = False continue memo = i tmp = 2 * i while tmp <= a[-1]: flag[tmp] = False tmp += i ans = 0 for i in a: if flag...
p02642
import collections n=int(eval(input())) arr=list(map(int,input().split())) arr=sorted(arr) s=set() cnt=collections.Counter(arr) for i in range(n): if arr[i] in s: continue for j in range(2,10**6//arr[i]+1): s.add(arr[i]*j) ans=0 for i in range(n): if arr[i] in s: continue if cnt[arr...
import collections n=int(eval(input())) arr=list(map(int,input().split())) arr=sorted(arr) s=set() cnt=collections.Counter(arr) for i in range(n): if arr[i] in s: continue if cnt[arr[i]]>=2: s.add(arr[i]) for j in range(2,10**6//arr[i]+1): s.add(arr[i]*j) ans=0 for i in range(n): if...
p02642
# coding:utf-8 n = int(eval(input())) a = list(map(int, input().split())) count = [0 for _ in range(max(a) + 1)] ans = 0 for i in a: if count[i] != 0: count[i] = 1 continue for j in range(2 * i, max(a) + 1, i): count[j] = 1 count[i] = 2 for i in a: if count[i] !=...
# coding:utf-8 n = int(eval(input())) a = list(map(int, input().split())) m = max(a) count = [0 for _ in range(m + 1)] ans = 0 for i in a: if count[i] != 0: count[i] = 1 continue for j in range(2 * i, m + 1, i): count[j] = 1 count[i] = 2 for i in a: if count[i] ...
p02642
import math #import numpy as np import queue from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) def main(): n = int(ipt()) ...
import math #import numpy as np import queue from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) def main(): n = int(ipt()) ...
p02642
n = int(eval(input())) al = [int(i) for i in input().split()] 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[:-1] ...
n = int(eval(input())) al = [int(i) for i in input().split()] al.sort() ma = al[-1] from collections import Counter c = Counter(al) if n == 1: print((1)) else: sn = set() total = 0 l = len(al) for num in al: if num in sn: continue if c[num] == 1: total += 1 tmp = n...
p02642
N=int(eval(input())) A=list(map(int,input().split())) dic={} for i in range(N): if A[i] not in dic: dic[A[i]]=1 else: dic[A[i]]+=1 if N==1: print((1)) exit() if 1 in dic: if dic[1]>1: print((0)) exit() else: print((1)) exit()...
N=int(eval(input())) A=list(map(int,input().split())) M=max(A) check=[0]*(M+1) for i in range(N): a=A[i] while a<=M: check[a]+=1 a+=A[i] ans=0 for i in range(N): if check[A[i]]==1: ans+=1 print(ans)
p02642
n = int(eval(input())) a = sorted(list(map(int, input().split())))[::-1] ans = 0 while(len(a)): a_min = a.pop() if len(a) == 0: ans += 1 break if a_min == a[-1]: ans -= 1 a = [el for el in a if el % a_min != 0] ans += 1 print(ans)
n = int(eval(input())) a = sorted(list(map(int, input().split()))) max_a = a[-1] q = [0] * (max_a + 1) for i in a: if q[i] == 1 or q[i] == -1: q[i] = -1 continue for j in range(2*i, max_a+1, i): q[j] = -1 q[i] = 1 total = 0 for i in q: if i == 1: total +...
p02642
n = int(eval(input())) A = list(map(int,input().split())) A.sort() ac = A.count(1) if ac == 1: print((1)) exit() if ac >= 2: print((0)) exit() num = [0]*1000005 for a in A: num[a] += 1 b = [False]*1000005 seen = [False]*1000005 cnt = 0 A = list(set(A)) A.sort() for a in A: ...
n = int(eval(input())) A = list(map(int,input().split())) num = [0]*(10**6+1) for a in A: num[a] += 1 bai = [False]*(10**6+1) cnt = 0 A = list(set(A)) A.sort() for a in A: if bai[a]: continue if num[a] == 1: cnt += 1 for i in range(a, 10**6+1, a): bai[i] = ...
p02642
n = int(eval(input())) a = list(map(int, input().split())) if(len(a) == 1): print((1)) else: a.sort() flug = 1 for j in range(n): numl = [] if(j >= len(a)): break else: flug = 1 for i in range(j+1, len(a)): if(a[i]...
n = int(eval(input())) a = list(map(int, input().split())) result=0 flug = 0 if(len(a) == 1): print((1)) else: a.sort() dp = [True] * a[-1] flug = 1 for j in range(n): if(dp[a[j]-1] == True): if(a[j] == a[j-1]): if(flug == 0): res...
p02642
n = int(eval(input())) lst = [int(i) for i in input().split()] lst.sort() #print(lst) if 1 in lst: count = 0 for i in range(n): if lst[i] == 1: count += 1 if count == 2: break if count == 1: print((1)) else: print((0)) else: tf_lst = [1] * lst[n - 1] count = 0 ...
n = int(eval(input())) lst = [int(i) for i in input().split()] lst.sort() #print(lst) if 1 in lst: count = 0 for i in range(n): if lst[i] == 1: count += 1 if count == 2: break if count == 1: print((1)) else: print((0)) else: tf_lst = [1] * lst[n - 1] count = 0 ...
p02642
import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) 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*...
import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) N=int(input().rstrip()) a=[int(i) for i in input().split()] l=max(a)+1 cnt=[0]*l for i in a: for j in range(i,l,i):cnt[j]+=1 ans=0 for i in a: if cnt[i]==1: ans+=1 print(ans)
p02642
n = int(eval(input())) A = list(map(int, input().split())) 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(reverse=True) return divis...
n = int(eval(input())) A = list(map(int, input().split())) 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(reverse=True) return divis...
p02642
n = int(eval(input())) A = list(map(int, input().split())) from collections import Counter C = Counter(A) X = [0]*(10**6+1) A.sort() ans = 0 for a in A: if X[a] == 0 and C[a] == 1: ans += 1 X[a] += 1 j = 2*a while j <= 10**6: X[j] += 1 j += a print(ans)
n = int(eval(input())) A = list(map(int, input().split())) from collections import Counter C = Counter(A) X = [0]*(10**6+1) A = list(set(A)) A.sort() ans = 0 for a in A: if X[a] == 0 and C[a] == 1: ans += 1 X[a] += 1 j = 2*a while j <= 10**6: X[j] += 1 j += a ...
p02642
import sys from collections import deque import copy def main(): N = int(eval(input())) A = [int(i) for i in input().split()] A.sort() MAX = (10 ** 6) + 5 prime = [True] * MAX ans = 0 for i in range(1, N): if A[i] == A[i - 1]: prime[A[i]] = False ...
import sys from collections import deque import copy def main(): N = int(eval(input())) A = [int(i) for i in input().split()] A.sort() MAX = (10 ** 6) + 5 prime = [True] * MAX ans = 0 for i in range(1, N): if A[i] == A[i - 1] and prime[A[i]]: prime[A[i]] = Fal...
p02642
n=int(eval(input())) a=list(map(int,input().split())) l=[[0 for _ in range(n)] for _ in range(n)] for i in range(n): if 1 in l[i]: continue for j in range(i+1,n): if a[i]%a[j]==0: l[i][j]=1 if a[j]%a[i]==0: l[j][i]=1 cnt=0 for i in range(n): i...
n=int(eval(input())) a=list(map(int,input().split())) l=[0 for _ in range(n)] a.sort() for i in range(n): for j in range(n): if a.count(a[i])>=2: l[i]=1 break if ((a[i]//2)<a[j]): break if a[i]%a[j]==0: l[i]=1 break...
p02642
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in range(n): for j in sorted(a): if a[i] % j == 0: if a[i] != j: ans += 1 break else: if a.count(j) > 1: ans += 1 break print((n - ans))
N = int(eval(input())) A = sorted(list(map(int, input().split()))) m = max(A)+1 dp = [1]*m for a in A: if dp[a-1] == 1: dp[a-1] = 2 for i in range(a*2, m, a): dp[i-1] = 0 elif dp[a-1] == 2: dp[a-1] = 0 print((sum([1 for a in A if dp[a-1]])))
p02642
N = int(eval(input())) A = list(map(int,input().split())) L = [0] * (10 ** 6 + 1) S = set() for a in A: if a in S: L[a] = 1 S.add(a) for i in range(2, 10 ** 6 + 1): if a * i > 10 ** 6: break L[a * i] = 1 ans = 0 for a in A: if L[a] == 0: ans...
N = int(eval(input())) A = list(map(int,input().split())) A.sort() L = [0] * (10 ** 6 + 1) S = set() for a in A: if L[a]: continue if a in S: L[a] = 1 S.add(a) for i in range(2, 10 ** 6 + 1): if a * i > 10 ** 6: break L[a * i] = 1 ans = 0 f...
p02642
import sys import heapq from collections import Counter from math import sqrt n = int(eval(input())) a_s = [int(i) for i in sys.stdin.readline().split()] a_s.sort() _max = max(a_s) ct = Counter(a_s) cnt = 0 ls = [0] * (10**6+1) for a in a_s: if ls[a] == 1: cnt += 1 continue elif...
import sys import heapq from collections import Counter from math import sqrt n = int(eval(input())) a_s = [int(i) for i in sys.stdin.readline().split()] a_s.sort() _max = max(a_s) ct = Counter(a_s) cnt = 0 ls = [False] * (10**6+1) for a in a_s: if ls[a]: cnt += 1 continue elif ...
p02642
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from...
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from...
p02642
n = int(eval(input())) a_ls = list(map(int, input().split())) a_ls.sort(reverse=True) ans = 0 for i in range(n): not_divisible = True for j in range(i+1,n): if a_ls[i] % a_ls[j] == 0 or a_ls[i] == a_ls[j]: not_divisible = False break if i > 0 and a_ls[i-1] == a_ls[i...
n = int(eval(input())) a_ls = list(map(int, input().split())) a_ls.sort() a_max = a_ls[-1] times_ls = [0] * (a_max + 1) divisible_ls = [0] * (a_max + 1) for i in range(n): base = a_ls[i] times_ls[base] += 1 times = 2 while base*times <= a_max: divisible_ls[base*times] = 1 tim...
p02642
n = int(eval(input())) a = list(map(int, input().split())) a.sort() m = 10**6+10 d = [False] * (m+1) ans = 0 for i in range(n): same = (i > 0 and a[i] == a[i-1]) or (i < (n-1) and a[i] == a[i+1]) x = a[i] if not d[x] and not same: ans += 1 for j in range(x, m+1, x): d[j] = True ...
import sys input = lambda: sys.stdin.buffer.readline() n = int(eval(input())) a = list(map(int, input().split())) a.sort() m = 10**6+10 d = [False] * (m+1) ans = 0 for i in range(n): same = (i > 0 and a[i] == a[i-1]) or (i < (n-1) and a[i] == a[i+1]) x = a[i] if not d[x] and not same: ans += ...
p02642
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) a.sort() c = Counter(a) s = [] m = max(a) + 1 ans = 0 for ai in a: if ai in s: continue if c[ai] == 1: ans += 1 for i in range(ai, m, ai): s.insert(0, i) print(ans)
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) a.sort() c = Counter(a) m = max(a) + 1 dp = [False]*m ans = 0 for ai in a: if dp[ai]: continue if c[ai] == 1: ans += 1 for i in range(ai, m, ai): dp[i] = True print(ans)
p02642
N = int(eval(input())) A = list(map(int,input().split())) Adic={} for i in range(N): if A[i] not in Adic: Adic[A[i]] = 1 else: Adic[A[i]] += 1 Aset = set(A) if 1 in Aset: #1がある場合 if Adic[1] == 1: print((1)) else: print((0)) exit() ans = 0 for j in range(N): Flag = True te...
N = int(eval(input())) A = list(map(int,input().split())) MAX = max(A) #Aの中の最大値 Adic={} for i in range(N): if A[i] not in Adic: Adic[A[i]] = 1 else: Adic[A[i]] += 1 Aset = set(A) if 1 in Aset: #1がある場合 if Adic[1] == 1: print((1)) else: print((0)) exit() ans = 0 for j in range(N...
p02642
from collections import Counter n = int(eval(input())) a = sorted(list(map(int,input().split())),reverse=True) c = Counter(a) s = list (set(a)) dp = [True] * (10**6+1) for x in s: e = x*2 # エラトステネスの篩 while e <= 10 ** 6: dp[e] = False e += x ret = 0 for x in a: # 重複なし かつ...
from collections import Counter n = int(eval(input())) a = list(map(int,input().split())) c = Counter(a) s = list (set(a)) dp = [True] * (10**6+1) for x in s: e = x*2 # エラトステネスの篩 while e <= 10 ** 6: dp[e] = False e += x ret = 0 for x in a: # 重複なし かつ 素数 if c[x] == 1...
p02642
from collections import Counter n = int(eval(input())) a = list(map(int,input().split())) c = Counter(a) s = list (set(a)) dp = [True] * (10**6+1) for x in s: e = x*2 # エラトステネスの篩 while e <= 10 ** 6: dp[e] = False e += x ret = 0 for x in a: # 重複なし かつ 素数 if c[x] == 1...
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) c = Counter(a) dp = [True] * (10 ** 6 + 1) s = list(set(a)) for x in s: e = x * 2 while e <= 10 ** 6: dp[e] = False e += x ret = 0 for x in a: if c[x] == 1 and dp[x] == True: ret ...
p02642
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) c = Counter(a) dp = [True] * (10 ** 6 + 1) s = list(set(a)) for x in s: e = x * 2 while e <= 10 ** 6: dp[e] = False e += x ret = 0 for x in a: if c[x] == 1 and dp[x] == True: ret ...
from collections import Counter n = int(eval(input())) a = sorted(list(map(int, input().split()))) c = Counter(a) maxa = a[-1]+1 dp = [True] * maxa s = list(set(a)) for x in s: for j in range(x*2,maxa,x): dp[j] = False ret = 0 for x in a: if c[x] == 1 and dp[x] == True: ret += 1 pr...
p02642
n, *a = list(map(int, open(0).read().split())) a.sort() s = set() checked = set() dup = set() count = 0 ...
n, *a = list(map(int, open(0).read().split())) a.sort() am = a[-1] + 1 dp = [True] * am ans = 0 dup = set() for x in a: d = dp[x] if d: ans += 1 for i in range(x, am, x): dp[i] = False dp[x] = None elif d == None: dup.add(x) print((ans - len(dup))...
p02642
from collections import deque N = int(eval(input())) A = [[int(x)] for x in input().split()] def merge(s, t): u = [] while s + t: if s == [] or t == []: return u + s + t if s[0] <= t[0]: u.append(s[0]) s = s[1:] else: # s0 ...
N = int(eval(input())) A = [int(x) for x in input().split()] M = max(A) count = [0] * (M + 1) for i in range(N): count[A[i]] += 1 check = [True] * (M + 1) for a in range(1, M + 1): if count[a] > 0 and check[a] == True: for k in range(2, M // a + 1): check[a * k] = False ...
p02642
n = int(eval(input())) a = list(map(int, input().split())) a.sort() a_set = set(a) for i in range(n-1): if a[i] == a[i + 1]: if a[i] in a_set: a_set.remove(a[i]) dp = [True for _ in range(max(a) + 1)] ans = 0 y = -1 for x in a: if x == y: continue y = x i...
n = int(eval(input())) a = list(map(int, input().split())) a.sort() a_set = set(a) for i in range(n-1): if a[i] == a[i + 1]: if a[i] in a_set: a_set.remove(a[i]) ma = max(a) dp = [True for _ in range(ma + 1)] ans = 0 y = -1 for x in a: if x == y: continue y =...
p02642
from collections import defaultdict import sys N=int(eval(input())) alist=list(map(int,input().split())) adic=defaultdict(int) for a in alist: adic[a]+=1 noset=set() aset=set() max_a=0 for a,v in list(adic.items()): aset.add(a) max_a=max(max_a,a) if v>=2: noset.add(a) if not aset: ...
N=int(eval(input())) alist=list(map(int,input().split())) max_a=max(alist) exclude_set=set() tlist=[False]*(max_a+1) for a in alist: if tlist[a]: exclude_set.add(a) else: tlist[a]=True #print(tlist) for i in range(1,max_a//2+1): if not tlist[i]: continue else: for j in range(2...
p02642
def main(): n = int(eval(input())) a = tuple(map(int, input().split())) ans = 0 for i in range(len(a)): if a.count(a[i]) > 1: continue divisors = set() for j in range(1, int(a[i] ** 0.5) + 1): if a[i] % j == 0: divisors.add(j) ...
def main(): n = int(eval(input())) a = tuple(map(int, input().split())) ans = 0 mx = max(a) + 1 dp = [0] * mx for i in a: for j in range(i, mx, i): dp[j] += 1 for i in a: if dp[i] == 1: ans += 1 print(ans) if __name__ == "__mai...
p02642
def main(): n = int(eval(input())) a = tuple(map(int, input().split())) ans = 0 mx = max(a) + 1 dp = [0] * mx for i in a: for j in range(i, mx, i): dp[j] += 1 for i in a: if dp[i] == 1: ans += 1 print(ans) if __name__ == "__mai...
def main(): _ = int(eval(input())) a = list(map(int, input().split())) a.sort() a = tuple(a) ans = 0 mx = max(a) + 1 dp = [0] * mx for i in a: if dp[i] == 2: continue else: for j in range(i, mx, i): dp[j] += 1 fo...
p02642
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) c = Counter(a) nu = {k for k, v in list(c.items()) if v > 1} s = set() for aa in a: m = 2 while aa*m <= 10**6: s.add(aa*m) m += 1 o = 0 for aa in a: if aa in s or aa in nu: ...
from collections import Counter n = int(eval(input())) a = list(map(int, input().split())) mx = max(a) c = Counter(a) nu = {k for k, v in list(c.items()) if v > 1} s = set() u = set() for aa in a: m = 2 if aa in s or aa in u: continue u.add(aa) while aa*m <= mx: s.add...
p02642
n = int(eval(input())) a = sorted(map(int, input().split())) cnt = [0] * (max(a) + 1) for i in a: cnt[i] += 1 for i in set(a): if cnt[i] >= 1: for j in range(i * 2, max(a) + 1, i): cnt[j] = 0 print((cnt.count(1)))
n = int(eval(input())) a = sorted(map(int, input().split())) cnt = [0] * (a[-1] + 1) for i in a: cnt[i] += 1 for i in set(a): if cnt[i] >= 1: for j in range(i * 2, a[-1] + 1, i): cnt[j] = 0 print((cnt.count(1)))
p02642
import collections N = int(eval(input())) A = sorted([int(i) for i in input().split()]) C = collections.Counter(A) tested = [True for i in range(10**7+1)] ans = 0 for i in range(N): if C[A[i]] == 1 and tested[A[i]] is True: ans += 1 for j in range(A[i], 10**6+1, A[i]): tested[j] = ...
import collections N = int(eval(input())) A = sorted([int(i) for i in input().split()]) C = collections.Counter(A) tested = [True for i in range(10**7+1)] ans = 0 for i in range(N): if tested[A[i]] is True: for j in range(A[i], 10**6+1, A[i]): tested[j] = False if C[A[i]] == ...
p02642
from collections import Counter def main(): N = int(eval(input())) *A, = list(map(int, input().split())) A.sort() C = Counter(A) MAX = 2000005 T = [0]*MAX ans = 0 for a in A: if T[a]: continue else: if C[a] == 1: ...
from collections import Counter def main(): N = int(eval(input())) *A, = list(map(int, input().split())) C = Counter(A) MAX = 1000005 T = [0]*MAX ans = 0 for a in list(C.keys()): if T[a]: continue else: for i in range(2*a, MAX, a): ...
p02642
import sys def input(): return sys.stdin.readline()[:-1] def main(): N = int(eval(input())) A = list(map(int, input().split())) A_dict = {} for a in A: if a in list(A_dict.keys()): A_dict[a] += 1 else: A_dict[a] = 1 A_remain = sorted(...
def main(): N = int(eval(input())) A = list(map(int, input().split())) A_dict = {} for a in A: if a in list(A_dict.keys()): A_dict[a] += 1 else: A_dict[a] = 1 A_list = sorted(A_dict.keys()) limit = A_list[-1] sieve = {i: True for i in ...
p02642
import bisect as bc from collections import defaultdict from collections import deque N = int(eval(input())) A = list(map(int,input().split())) A.sort() q = set([i for i in range(N)]) for i in range(N): ai = A[i] itr = list(q) for j in itr: if j == i: continue if ...
import bisect as bc N = int(eval(input())) A = list(map(int,input().split())) A.sort() dp = [True for _ in range(A[-1]+1)] for i in range(N): ai = A[i] for j in range(2,A[-1]+1): if ai*j > A[-1]: break if dp[ai*j]: dp[ai*j] = False ans = 0 finish = [T...
p02642
import bisect as bc N = int(eval(input())) A = list(map(int,input().split())) A.sort() dp = [True for _ in range(A[-1]+1)] for i in range(N): ai = A[i] for j in range(2,A[-1]+1): if ai*j > A[-1]: break dp[ai*j] = False ans = 0 finish = [True for _ in range(A[-1]+1...
import bisect as bc N = int(eval(input())) A = list(map(int,input().split())) A.sort() dp = [True for _ in range(A[-1]+1)] for i in range(N): ai = A[i] for j in range(2,A[-1]+1): if ai*j > A[-1]: break dp[ai*j] = False ans = 0 for i in range(N): if dp[A[i...
p02642
n = int(eval(input())) a_l = list(map(int, input().split())) # 0 ~ 10**6のリスト A_list = [True for i in range(10**6+1)] # 倍数のところにFalseを入れる for i in a_l: for j in range(i*2, 10**6+1, i): A_list[j] = False # 0 ~ 10**6に入力値の個数を入れる # (count()で数えると、o(n**2)になるため) val_list = [0 for i in range(10**6+1)] for i in ...
n = int(eval(input())) a_l = list(map(int, input().split())) # 0 ~ 10**6に入力値の個数を入れる # (count()で数えると、o(n**2)になるため) val_list = [0 for i in range(10**6+1)] for i in a_l: val_list[i] += 1 # 重複削除 a_l = list(set(a_l)) # 0 ~ 10**6のリスト A_list = [True for i in range(10**6+1)] # 倍数のところにFalseを入れる for i in a_l: ...
p02642
import math n = int(eval(input())) ai = [int(i) for i in input().split()] ai.sort() sqr_max_val = int(ai[n-1]**0.5) max_val = ai[n-1] #print(ai) ai_ex = [0]*(2*10**6) #ai_ex = [0]*(30) for i in range(n): ai_ex[ai[i]-1] += 1 for i in range(n): if ai_ex[ai[i]-1] > 1: ai_ex[ai[i]-1] = ...
import math n = int(eval(input())) ai = [int(i) for i in input().split()] ai.sort() sqr_max_val = int(ai[n-1]**0.5) max_val = ai[n-1] #print(ai) ai_ex = [0]*(2*10**6) #ai_ex = [0]*(30) for i in range(n): ai_ex[ai[i]-1] += 1 for i in range(n): if ai_ex[ai[i]-1] == 0: continue if...
p02642
from itertools import combinations def main(): n = int(eval(input())) a = list(map(int, input().split())) a = sorted(a, reverse=True) x = {} for i in a: x[i] = True for i in range(0, n - 1): for j in range(i + 1, n): if a[i] % a[j] == 0: ...
def main(): n = int(eval(input())) a = list(map(int, input().split())) a = sorted(a) max_a = max(a) + 1 dp = [True] * max_a for idx in range(len(a)): if idx + 1 != len(a) and a[idx] == a[idx + 1]: dp[a[idx]] = False i = a[idx] x = 2 whil...
p02642
import math n = int(eval(input())) a = list(map(int, input().split())) ans = 0 d = {} for i in range(len(a)): if a[i] in list(d.keys()): d[a[i]] += 1 else: d[a[i]] = 1 # print(d) for i in range(len(a)): flag = False if d[a[i]] > 1: continue if a...
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 d = {} for i in range(len(a)): if a[i] in list(d.keys()): d[a[i]] += 1 else: d[a[i]] = 1 max_ = max(a) arr = [True] * (max_+1) ans = 0 for i in range(1, max_+1): if i in list(d.keys()) and arr[i]: ...
p02642
import sys n=int(eval(input())) a=[int(x) for x in input().rstrip().split()] a.sort() max_val=max(a) dp=[True for i in range(max_val)] done=[0 for i in range(max_val)] cnt=0 ans=0 for i in a: if 1<=done[i-1]: done[i-1]+=1 continue done[i-1]+=1 cnt=1 while(i*cnt<=max_val): cnt...
import sys n=int(eval(input())) a=[int(x) for x in input().rstrip().split()] a.sort() max_val=max(a) done=[0 for i in range(max_val)] cnt=0 ans=0 for i in a: if 1<=done[i-1]: done[i-1]+=1 continue done[i-1]+=1 cnt=1 while(i*cnt<=max_val): cnt+=1 if cnt*i<=max_val: ...
p02642
import math def isPrime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True N = int(eval(input())) A = sorted(list(map(int, input().split()))) cnt = N if N == 1: print(N) exit() if A[0] == 1 and A[1] == 1: print((0)...
N = int(eval(input())) A = sorted(list(map(int, input().split()))) m = A[-1] B = [0] * m for a in A: B[a - 1] += 1 if B[a - 1] == 1: for j in range(a * 2, m + 1, a): B[j - 1] = 2 print((B.count(1)))
p02642
def main(): n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for i in a: cnt = 0 for j in range(n): if i % a[j] == 0: cnt += 1 if cnt == 1: ans += 1 print(ans) if __name__ == '__main__': main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) a_s = sorted(a) a_set = set(a_s) maxv = max(a) res = [0] * maxv rep = 0 for i in a_s: if i in a_set: if res[i-1] == 0: for j in range(i, maxv+1, i): ...
p02642
N= int(eval(input())) A=list(map(int,input().split())) count=0 for i in range(N): flag=True for j in range(N): if i!=j and A[i]%A[j]==0: flag=False if flag==True: count+=1 print(count)
N= int(eval(input())) A=list(map(int,input().split())) dp=[0]*(max(A)+1) for a in A: for x in range(a,len(dp),a): dp[x]+=1 count=0 for a in A: if dp[a]==1: count+=1 print(count)
p02642
import collections # Your code her a = int(eval(input())) b = [int(s) for s in input().split()] b = sorted(b) mod = int(1000000) d = {} e = collections.Counter(b) X = int(0) ans = int(0) for i in range(a): if d.get(b[i]) == None: X = b[i] while X <= (mod-b[i]): X += b[i] ...
import collections # Your code her a = int(eval(input())) b = [int(s) for s in input().split()] b = sorted(b) mod = int(1000000) d = {} e = collections.Counter(b) X = int(0) ans = int(0) for i in range(a): if d.get(b[i]) == None: if e.get(b[i]) != 1: d[b[i]] = 1 X = b[i] ...
p02642
N = int(eval(input())) A = [int(i) for i in input().split()] from collections import defaultdict cnt_A = defaultdict(int) for a in A: cnt_A[a] += 1 NG_list = [] for key in list(cnt_A.keys()): if cnt_A[key] >= 2: NG_list.append(key) NG_list = set(NG_list) sort_A = sorted(A) from collections i...
n = int(eval(input())) a = [int(i) for i in input().split()] max_a = max(a) cnt_d = [0] * (max_a + 1) for ai in a: for multi in range(ai, max_a + 1, ai): cnt_d[multi] += 1 print((sum(cnt_d[ai] == 1 for ai in a)))
p02642
n = int(eval(input())) A = list(map(int, input().split())) A=sorted(A) table=[0]*(10**6+1) for i in range(n): table[A[i]]+=1 for i in range(n): if A[i]>0: j=2 while A[i]*j<10**6+1: if table[A[i]*j]>0: table[A[i]*j]=-1 j+=1 cnt=0 for x i...
n = int(eval(input())) A = list(map(int, input().split())) A=sorted(A) up=max(A) table=[0]*(up+1) for i in range(n): table[A[i]]+=1 aset=set(A) for i in range(len(aset)): if table[A[i]]>0: j=2 while A[i]*j<up+1: if table[A[i]*j]>0: table[A[i]*j]=-1 ...
p02642