Project Euler #116: Red, green or blue tiles

  • + 1 comment
    import math
    def C(n,r):
        f = math.factorial
        return f(n) // f(r) // f(n-r)
    
    t=int(input())
    for i in range(t):
        n=int(input())
        r=g=b=0
        for rr in range(1,(n//2)+1):
            r+=C(n-rr,rr)
        for gg in range(1,(n//3)+1):
            g+=C(n-(2*gg),gg)
        for bb in range(1,(n//4)+1):
            b+=C(n-(3*bb),bb)
        print((r+g+b)%1000000007)
    

    I think it take less time with compare to next (;一_一) but nope, it's take 8.33% more loop than 0-n

    for i in range(int(input())):
        a=b=m=n=o=w=x=y=z=1
        for j in range(1,int(input())):
            a,b,m,n,o,w,x,y,z = b,a+b,n,o,o+m,x,y,z,z+w
        print((b+n+x-3)%1000000007)
    

    smallest in size (lines of code)?

    but still TLE ಠ_ಥ