Commit 80029271 by Nayuki Minase

### P15, P53, P113: Moved binomial() function into eulerlib.

parent 1dc03886
 ... ... @@ -51,3 +51,8 @@ def factorial(n): for i in range(1, n + 1): result *= i return result def binomial(n, k): assert n >= 0 and 0 <= k <= n return factorial(n) // (factorial(k) * factorial(n - k))
 ... ... @@ -10,11 +10,7 @@ import eulerlib def compute(): return str(binomial(40, 20)) def binomial(n, k): return eulerlib.factorial(n) // (eulerlib.factorial(k) * eulerlib.factorial(n - k)) return str(eulerlib.binomial(40, 20)) if __name__ == "__main__": ... ...
 ... ... @@ -13,14 +13,10 @@ def compute(): ans = 0 for n in range(1, 101): for k in range(0, n + 1): if binomial(n, k) > 1000000: if eulerlib.binomial(n, k) > 1000000: ans += 1 return str(ans) def binomial(n, k): return eulerlib.factorial(n) // (eulerlib.factorial(k) * eulerlib.factorial(n - k)) if __name__ == "__main__": print(compute())
 ... ... @@ -35,16 +35,12 @@ import eulerlib # (Technically, in the problem statement and this solution, "increasing" actually means "nondecreasing" and "decreasing" means "nonincreasing".) def compute(): DIGITS = 100 increasing = binomial(DIGITS + 9, 9) - 1 decreasing = binomial(DIGITS + 10, 10) - (DIGITS + 1) increasing = eulerlib.binomial(DIGITS + 9, 9) - 1 decreasing = eulerlib.binomial(DIGITS + 10, 10) - (DIGITS + 1) flat = DIGITS * 9 ans = increasing + decreasing - flat return str(ans) def binomial(n, k): return eulerlib.factorial(n) // (eulerlib.factorial(k) * eulerlib.factorial(n - k)) if __name__ == "__main__": print(compute())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!