Project Euler #53: Combinatoric selections

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import math
    
    n, k = map(int, input().split())
    
    def combi(n, r):
        if r == 0 or r == n:
            return(1)
        s, r = 1, (n-r if n-r < r else r)
        for i in range(r):
            s *= ((n-i) / (i+1))
        return(math.ceil(s))
     
    c = 0
    for i in range(1, n+1):
        for j in range(i+1):
            if combi(i, j) > k:
                c += 1
    
    print(c)