結果

問題 No.575 n! / m / m / m...
ユーザー maspymaspy
提出日時 2023-06-13 16:27:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 47,216 KB
最終ジャッジ日時 2023-09-04 01:42:20
合計ジャッジ時間 10,706 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 220 ms
46,880 KB
testcase_01 AC 208 ms
46,820 KB
testcase_02 AC 206 ms
46,768 KB
testcase_03 AC 205 ms
46,436 KB
testcase_04 AC 209 ms
46,736 KB
testcase_05 AC 209 ms
46,792 KB
testcase_06 AC 205 ms
47,020 KB
testcase_07 AC 203 ms
46,836 KB
testcase_08 AC 206 ms
46,488 KB
testcase_09 AC 203 ms
46,484 KB
testcase_10 AC 206 ms
46,740 KB
testcase_11 AC 206 ms
46,836 KB
testcase_12 AC 206 ms
46,848 KB
testcase_13 AC 210 ms
46,736 KB
testcase_14 AC 208 ms
46,872 KB
testcase_15 AC 213 ms
46,744 KB
testcase_16 AC 208 ms
46,480 KB
testcase_17 AC 207 ms
46,836 KB
testcase_18 AC 207 ms
47,216 KB
testcase_19 AC 211 ms
46,756 KB
testcase_20 AC 211 ms
46,908 KB
testcase_21 AC 213 ms
46,748 KB
testcase_22 AC 207 ms
47,012 KB
testcase_23 AC 208 ms
47,036 KB
testcase_24 AC 210 ms
46,760 KB
testcase_25 AC 208 ms
47,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
from scipy.special import loggamma

N, M = map(int, read().split())

U = 10 ** 6 + 10
is_prime = np.zeros(U, np.bool_)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
    if p * p > U:
        break
    if is_prime[p]:
        is_prime[p * p::p + p] = 0
primes = np.where(is_prime)[0]


def factor(N):
    div = primes[N % primes == 0].tolist()
    for p in div:
        e = 0
        while N % p == 0:
            N //= p
            e += 1
        yield (p, e)
    if N > 1:
        yield (N, 1)


def fact_ord(p, N):
    ret = 0
    while N:
        N //= p
        ret += N
    return ret


T = N + 10
for p, e in factor(M):
    f = fact_ord(p, N)
    if T > f // e:
        T = f // e

log_x = (loggamma(N + 1) - T * np.log(M))
d = int(log_x // np.log(10))
log_x -= np.log(10) * d
x = np.exp(log_x)
print(f'{x:.3f}e{d}')
0