結果

問題 No.575 n! / m / m / m...
ユーザー shotoyooshotoyoo
提出日時 2021-06-19 18:56:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,949 ms / 2,000 ms
コード長 1,563 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 11,060 KB
実行使用メモリ 76,292 KB
最終ジャッジ日時 2023-09-05 01:08:56
合計ジャッジ時間 12,203 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,949 ms
45,696 KB
testcase_01 AC 211 ms
45,564 KB
testcase_02 AC 204 ms
45,764 KB
testcase_03 AC 206 ms
45,652 KB
testcase_04 AC 207 ms
45,736 KB
testcase_05 AC 207 ms
45,612 KB
testcase_06 AC 205 ms
45,684 KB
testcase_07 AC 205 ms
45,596 KB
testcase_08 AC 211 ms
45,588 KB
testcase_09 AC 210 ms
45,600 KB
testcase_10 AC 209 ms
45,696 KB
testcase_11 AC 206 ms
45,732 KB
testcase_12 AC 207 ms
45,604 KB
testcase_13 AC 206 ms
45,752 KB
testcase_14 AC 205 ms
45,728 KB
testcase_15 AC 204 ms
45,816 KB
testcase_16 AC 201 ms
45,592 KB
testcase_17 AC 207 ms
45,692 KB
testcase_18 AC 209 ms
45,740 KB
testcase_19 AC 207 ms
45,672 KB
testcase_20 AC 207 ms
45,720 KB
testcase_21 AC 215 ms
45,652 KB
testcase_22 AC 207 ms
45,600 KB
testcase_23 AC 410 ms
45,852 KB
testcase_24 AC 204 ms
45,632 KB
testcase_25 AC 409 ms
76,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n,m = list(map(int, input().split()))
import math
def factor(n, m=None):
    # mを与えると、高々その素因数まで見て、残りは分解せずにそのまま出力する
    f = {}
    tmp = n
    M = int(-(-n**0.5//1))+1
    if m is not None:
        M = min(m+1, M)
    for i in range(2, M+1):
        if tmp<i:
            break
        if tmp%i==0:
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp //= i
            f[i] = cnt
    if tmp!=1:
        f[tmp] = 1
    if not f:
        f[n] = 1
    return f
def divnum(n,m):
    """n!がmで割れる回数
    """
    f = factor(m)
    ans = float("inf")
    for k in f:
        kk = k
        val = 0
        while kk<=n:
            val += n//kk
            kk *= k
        ans = min(ans, val//f[k])
    return ans
def dn(v,k):
    """vがkで割れる回数
    """
    ans = 0
    while v%k==0:
        ans += 1
        v //= k
    return ans
import scipy.special
f2 = factor(m)
val = divnum(n,m)
# if n<10**6:
#     ans = sum((math.log10(i) for i in range(1, n+1)))
# else:
#     ans = math.log(2*math.pi*n)/2 + n*math.log(n) - n
#     ans /= math.log(10)
ans = scipy.special.loggamma(n+1) / math.log(10)
ans -= val * math.log10(m)
v = math.pow(10, ans%1)
# print(v)
e = ans//1
print(f"{v}e{int(e)}")
# print("{:e}".format(p))
0