結果

問題 No.144 エラトステネスのざる
ユーザー あかりきあかりき
提出日時 2021-02-23 21:18:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 715 ms / 2,000 ms
コード長 408 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 81,388 KB
実行使用メモリ 84,324 KB
最終ジャッジ日時 2023-10-23 22:16:14
合計ジャッジ時間 7,262 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,424 KB
testcase_01 AC 38 ms
55,300 KB
testcase_02 AC 38 ms
55,448 KB
testcase_03 AC 37 ms
55,300 KB
testcase_04 AC 39 ms
55,300 KB
testcase_05 AC 38 ms
55,300 KB
testcase_06 AC 68 ms
72,776 KB
testcase_07 AC 69 ms
72,948 KB
testcase_08 AC 69 ms
72,964 KB
testcase_09 AC 70 ms
72,964 KB
testcase_10 AC 70 ms
72,964 KB
testcase_11 AC 69 ms
72,964 KB
testcase_12 AC 68 ms
72,944 KB
testcase_13 AC 652 ms
84,108 KB
testcase_14 AC 706 ms
84,260 KB
testcase_15 AC 702 ms
84,256 KB
testcase_16 AC 697 ms
84,260 KB
testcase_17 AC 693 ms
84,260 KB
testcase_18 AC 715 ms
84,324 KB
testcase_19 AC 702 ms
84,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
n,p=map(float,input().split())
n=int(n)
l=[i for i in range(n+1)]
for i in range(2,n+1):
  if l[i]==i:
    for j in range(1,n//i+1):
      if i*j<=n:
        l[i*j]=i

ans=0
for i in range(2,n+1):
  x=i
  d=[]
  while x!=1:
    d.append(l[x])
    x//=l[x]
  d=collections.Counter(d)
  d=list(d.values())
  ct=1
  for j in range(len(d)):
    ct*=(d[j]+1)
  ct-=2
  ans+=(1-p)**ct
print(ans)
0