Project Euler #53: Combinatoric selections

Sort by

recency

|

19 Discussions

|

  • + 0 comments

    Short and simple:

    def Solve_Prob(n,k):

        count = 0
    for i in range(2,n+1):
        x = i
        for r in range(1,(n//2)+1):
            if x > k:
                count = count + (i-2*r+1)
                break
            x = (x*(i-r))//(r+1)
    answer = count
    return answer
    

    t = 1 for i in range(0,t): n,k = map(int, input().split()) answer = Solve_Prob(n,k) print(answer)

  • + 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)
    
  • + 0 comments

    Easy.

    import math
    n,k=map(int,input().strip().split())
    count=0
    for i in range(1,n+1):
        for r in range(n):
            if math.comb(i,r)>k:
                count+=1
    print(count)
    
  • + 0 comments

    100 points/- python3

    from math import comb
    data=input().split()
    n=int(data[0])
    k=int(data[1])
    
    count=0
    for i in range(2,n+1):
        r=(i+1)//2
        if comb(i,r)>k:
            if i%2==0:
                count+=1
                r=r-1
            else:
                count+=2
                r=r-2
    
            while comb(i,r)>k:
                count+=2
                r+=-1
                if r<0:
                    break
    
    print(count)
    
  • + 0 comments

    Hint: one does not have to compute all nCr but rather consider how nCr changes as n and r changes.