์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Python

[BOJ/Step10] 10872 : ํŒฉํ† ๋ฆฌ์–ผ (Python)

NaNaRin๐Ÿ™ƒ 2021. 2. 17. 15:31

www.acmicpc.net/problem/10872

 

10872๋ฒˆ: ํŒฉํ† ๋ฆฌ์–ผ

0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, N!์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net


N! = N * (N - 1) * … * 2 * 1

x๋ฅผ ์ „๋‹ฌํ•˜๋ฉด x * fax(x-1)์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ fac() ์„ ์ •์˜

fac()์€ ์žฌ๊ท€ํ•จ์ˆ˜๋กœ x๊ฐ€ 0์ผ๋•Œ๊นŒ์ง€ fac()๋ฅผ ๋ฐ˜๋ณตํ•ด์„œ ํ˜ธ์ถœํ•œ๋‹ค

# 10872.py

def fac(x):
    if x == 0:
        return 1
    else:
        return x * fac(x-1)


x = int(input())
print(fac(x))