結果

問題 No.826 連絡網
ユーザー takakintakakin
提出日時 2020-07-14 22:15:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,303 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 24,440 KB
最終ジャッジ日時 2024-04-29 17:22:40
合計ジャッジ時間 12,852 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 26 ms
10,624 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 AC 32 ms
10,624 KB
testcase_04 AC 35 ms
10,624 KB
testcase_05 AC 29 ms
10,880 KB
testcase_06 AC 28 ms
10,880 KB
testcase_07 AC 35 ms
10,624 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 35 ms
10,752 KB
testcase_10 AC 27 ms
10,752 KB
testcase_11 AC 30 ms
10,880 KB
testcase_12 AC 874 ms
21,308 KB
testcase_13 AC 341 ms
14,416 KB
testcase_14 AC 653 ms
19,400 KB
testcase_15 AC 90 ms
11,628 KB
testcase_16 AC 440 ms
15,536 KB
testcase_17 AC 370 ms
14,668 KB
testcase_18 AC 295 ms
13,956 KB
testcase_19 AC 1,109 ms
22,572 KB
testcase_20 AC 991 ms
22,440 KB
testcase_21 AC 37 ms
10,880 KB
testcase_22 AC 349 ms
14,560 KB
testcase_23 AC 463 ms
15,480 KB
testcase_24 AC 210 ms
13,256 KB
testcase_25 AC 1,303 ms
24,216 KB
testcase_26 AC 244 ms
13,616 KB
testcase_27 AC 937 ms
21,444 KB
testcase_28 AC 722 ms
19,636 KB
testcase_29 AC 346 ms
14,408 KB
testcase_30 AC 1,289 ms
24,440 KB
testcase_31 AC 411 ms
15,100 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