結果
問題 |
No.575 n! / m / m / m...
|
ユーザー |
![]() |
提出日時 | 2023-06-13 16:27:04 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,267 ms / 2,000 ms |
コード長 | 996 bytes |
コンパイル時間 | 85 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 117,180 KB |
最終ジャッジ日時 | 2024-06-22 01:43:53 |
合計ジャッジ時間 | 31,363 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
外部呼び出し有り |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#!/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}')