結果

問題 No.826 連絡網
ユーザー takakintakakin
提出日時 2020-07-14 22:15:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 91,008 KB
最終ジャッジ日時 2024-04-29 17:23:12
合計ジャッジ時間 3,689 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,224 KB
testcase_01 AC 41 ms
52,224 KB
testcase_02 AC 42 ms
52,224 KB
testcase_03 AC 57 ms
62,592 KB
testcase_04 AC 58 ms
62,464 KB
testcase_05 AC 51 ms
60,672 KB
testcase_06 AC 52 ms
61,056 KB
testcase_07 AC 57 ms
62,336 KB
testcase_08 AC 52 ms
60,672 KB
testcase_09 AC 58 ms
62,592 KB
testcase_10 AC 52 ms
59,776 KB
testcase_11 AC 57 ms
62,080 KB
testcase_12 AC 119 ms
84,864 KB
testcase_13 AC 82 ms
72,192 KB
testcase_14 AC 102 ms
79,744 KB
testcase_15 AC 63 ms
64,896 KB
testcase_16 AC 84 ms
73,600 KB
testcase_17 AC 84 ms
72,576 KB
testcase_18 AC 78 ms
70,912 KB
testcase_19 AC 129 ms
87,680 KB
testcase_20 AC 121 ms
85,760 KB
testcase_21 AC 56 ms
61,952 KB
testcase_22 AC 79 ms
71,296 KB
testcase_23 AC 86 ms
73,600 KB
testcase_24 AC 74 ms
68,736 KB
testcase_25 AC 138 ms
90,624 KB
testcase_26 AC 76 ms
69,760 KB
testcase_27 AC 120 ms
85,632 KB
testcase_28 AC 106 ms
80,512 KB
testcase_29 AC 81 ms
72,704 KB
testcase_30 AC 140 ms
91,008 KB
testcase_31 AC 82 ms
72,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n,p=map(int,input().split())
pf={}

for i in range(2,int(p**0.5)+1):
  while p%i==0:
    pf[i]=pf.get(i,0)+1
    p//=i
if p>1:
  pf[p]=1

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

P=primes(n)
PF=set(pf.keys())
p_min=min(PF)
while True:
	for pp in P:
		if p_min*pp<=n:
			PF.add(pp)
	if min(PF)==p_min:
		break
	else:
		p_min=min(PF)

Chk=[0]*n
for i in range(n):
	if Chk[i]==1:
		continue
	else:
		if i+1 in PF:
			Chk[i]=1
			mul=2
			while mul*(i+1)<=n:
				Chk[mul*(i+1)-1]=1
				mul+=1
print(sum(Chk))

0