結果

問題 No.144 エラトステネスのざる
ユーザー sue_charosue_charo
提出日時 2017-04-17 13:11:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 720 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 58,704 KB
最終ジャッジ日時 2023-09-26 10:36:06
合計ジャッジ時間 6,488 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
14,360 KB
testcase_01 AC 29 ms
9,860 KB
testcase_02 AC 29 ms
9,940 KB
testcase_03 AC 29 ms
9,924 KB
testcase_04 AC 29 ms
9,896 KB
testcase_05 AC 29 ms
9,764 KB
testcase_06 AC 29 ms
9,900 KB
testcase_07 AC 32 ms
9,916 KB
testcase_08 AC 31 ms
9,892 KB
testcase_09 AC 30 ms
9,980 KB
testcase_10 AC 30 ms
9,916 KB
testcase_11 AC 30 ms
9,884 KB
testcase_12 AC 30 ms
9,844 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def solve(N, p):
    dp = [1.0] * (N + 1)
    p_minus = 1.0 - p
    for i in range(2, N + 1):
        j = i * 2
        while j <= N:
            dp[j] *= p_minus
            j += i

    ans = sum(dp[2:])
    
    return ans


def main():
    N, p = input().split()
    N = int(N)
    p = float(p)
    print(solve(N, p))


if __name__ == "__main__":
    main()
0