ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 13294 |
문제명 | 역팩토리얼 |
레벨 | 골드 3 |
분류 |
수학 |
시간복잡도 | O(logn) |
인풋사이즈 | n<=10^6 |
사용한 언어 | Python |
제출기록 | 33272KB / 108ms |
최고기록 | 64ms |
해결날짜 | 2021/11/18 |
"""Solution code for "BOJ 13294. 역팩토리얼".
- Problem link: https://www.acmicpc.net/problem/13294
- Solution link: http://www.teferi.net/ps/problems/boj/13294
"""
import itertools
import math
def main():
n_fac = input()
log_n_fac = len(n_fac) - 1 + math.log10(int(n_fac[0]))
s = 0
for i in itertools.count(1):
s += math.log10(i)
if s >= log_n_fac:
answer = i
break
print(answer)
if __name__ == '__main__':
main()
"""Solution code for "BOJ 13294. 역팩토리얼".
- Problem link: https://www.acmicpc.net/problem/13294
- Solution link: http://www.teferi.net/ps/problems/boj/13294
"""
import math
from teflib import algorithm
def log_fac(x):
return (math.log(math.factorial(x)) if x < 10 else
(x * (math.log(x) - 1) + math.log(2 * math.pi * x) / 2))
def main():
n_fac = input()
log_n_fac = math.log(10) * (len(n_fac) - 1) + math.log(int(n_fac[0]))
hi = len(n_fac) + 10
answer = algorithm.binary_search(1, hi, lambda x: log_fac(x) >= log_n_fac)
print(answer)
if __name__ == '__main__':
main()