結果

問題 No.575 n! / m / m / m...
ユーザー maspy
提出日時 2020-03-24 22:02:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 995 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 119,932 KB
最終ジャッジ日時 2025-01-01 18:26:22
合計ジャッジ時間 34,892 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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