LoginSignup
0
0

More than 1 year has passed since last update.

【Project Euler】Problem 53: 組み合わせ数

Posted at
  • 本記事はProjectEulerの「100番以下の問題の説明は記載可能」という規定に基づいて回答のヒントが書かれていますので、自分である程度考えてみてから読まれることをお勧めします。

問題 53. 組み合わせ数

原文 Problem 53: Combinatoric selections

問題の要約:$1 \le n \le 100$ で以下の組み合わせ数が$10^6$を超える数を求めよ

 \begin{pmatrix} n \\ r \end{pmatrix}

組み合わせ数はsympybinomialを、それに入力する$n,r$はcombinations_with_replacementで生成します。

from sympy import  binomial 
from itertools import combinations_with_replacement as combr
n, N = 100, 10**6
print(f"Answer: {len([c for c in [binomial(n,r) for (r,n) in combr(range(1,n+1),2)] if c>N])}")

(開発環境:Google Colab)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0