結果
問題 | No.575 n! / m / m / m... |
ユーザー | shotoyoo |
提出日時 | 2021-06-19 18:59:14 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 420 ms / 2,000 ms |
コード長 | 1,646 bytes |
コンパイル時間 | 236 ms |
コンパイル使用メモリ | 10,980 KB |
実行使用メモリ | 45,740 KB |
最終ジャッジ日時 | 2023-09-05 01:09:56 |
合計ジャッジ時間 | 8,251 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 214 ms
45,404 KB |
testcase_01 | AC | 213 ms
45,716 KB |
testcase_02 | AC | 210 ms
45,452 KB |
testcase_03 | AC | 210 ms
45,636 KB |
testcase_04 | AC | 204 ms
45,696 KB |
testcase_05 | AC | 205 ms
45,512 KB |
testcase_06 | AC | 202 ms
45,540 KB |
testcase_07 | AC | 205 ms
45,536 KB |
testcase_08 | AC | 204 ms
45,488 KB |
testcase_09 | AC | 203 ms
45,668 KB |
testcase_10 | AC | 204 ms
45,556 KB |
testcase_11 | AC | 205 ms
45,488 KB |
testcase_12 | AC | 212 ms
45,544 KB |
testcase_13 | AC | 212 ms
45,532 KB |
testcase_14 | AC | 213 ms
45,584 KB |
testcase_15 | AC | 212 ms
45,740 KB |
testcase_16 | AC | 221 ms
45,504 KB |
testcase_17 | AC | 214 ms
45,608 KB |
testcase_18 | AC | 211 ms
45,612 KB |
testcase_19 | AC | 212 ms
45,732 KB |
testcase_20 | AC | 214 ms
45,504 KB |
testcase_21 | AC | 217 ms
45,628 KB |
testcase_22 | AC | 209 ms
45,552 KB |
testcase_23 | AC | 406 ms
45,444 KB |
testcase_24 | AC | 218 ms
45,656 KB |
testcase_25 | AC | 420 ms
45,508 KB |
ソースコード
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) def logfact(n): """log(n!) """ 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) return ans # ans = scipy.special.loggamma(n+1) / math.log(10) ans = logfact(n) 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))