結果
問題 |
No.575 n! / m / m / m...
|
ユーザー |
|
提出日時 | 2021-06-19 18:56:11 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,563 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 108,108 KB |
最終ジャッジ日時 | 2024-06-22 22:16:53 |
合計ジャッジ時間 | 31,631 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 TLE * 1 |
other | AC * 23 |
ソースコード
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))