結果

問題 No.1946 ロッカーの問題
ユーザー とりゐとりゐ
提出日時 2022-05-20 21:42:11
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 314 ms / 3,000 ms
コード長 1,100 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 106,740 KB
最終ジャッジ日時 2023-10-20 12:08:57
合計ジャッジ時間 4,528 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
63,344 KB
testcase_01 AC 50 ms
63,344 KB
testcase_02 AC 314 ms
80,932 KB
testcase_03 AC 297 ms
102,940 KB
testcase_04 AC 312 ms
80,928 KB
testcase_05 AC 273 ms
80,436 KB
testcase_06 AC 281 ms
80,808 KB
testcase_07 AC 255 ms
80,288 KB
testcase_08 AC 158 ms
87,084 KB
testcase_09 AC 261 ms
106,740 KB
testcase_10 AC 249 ms
103,100 KB
testcase_11 AC 106 ms
78,220 KB
testcase_12 AC 200 ms
80,316 KB
testcase_13 AC 48 ms
63,344 KB
testcase_14 AC 47 ms
63,344 KB
testcase_15 AC 121 ms
78,164 KB
testcase_16 AC 48 ms
63,344 KB
testcase_17 AC 147 ms
87,876 KB
testcase_18 AC 219 ms
101,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Sieve of Eratosthenes
class SOE:
  def __init__(self,m):
    self.sieve=[-1]*(m+1)
    self.prime=[]
    for i in range(2,m+1):
      if self.sieve[i]==-1:
        self.prime.append(i)
        self.sieve[i]=i
        j=2*i
        while j<=m:
          self.sieve[j]=i
          j+=i
  
  def primes(self):
    # get primes
    return self.prime
  
  def fact(self,n):
    # prime factorization
    d={}
    while n!=1:
      k=self.sieve[n]
      if k not in d:
        d[k]=0
      d[k]+=1
      n//=k
    return d
  
  def div(self,n):
    # get divisors
    c=[1]
    while n!=1:
      p=self.sieve[n]
      cnt=1
      n//=p
      while self.sieve[n]==p:
        cnt+=1
        n//=p
      s=c.copy()
      for i in s:
        for j in range(1,cnt+1):
          c.append(i*(p**j))
    return c

soe=SOE(2*10**5+10)

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

c=[0]*(n+1)
for i in a:
  c[i]+=1

d=[0]*(n+1)
for i in range(1,n+1):
  for j in soe.div(i):
    d[j]^=1

ans=0
for i in range(n,0,-1):
  if c[i]!=d[i]:
    ans+=1
    for j in soe.div(i):
      d[j]^=1

print(ans)
0