Project Euler #224: Almost right-angled triangles II

  • + 0 comments

    timeout and almost all in red. But the code seems ok?. Guess to make a more efficient code we need a third equation related with the angles (to eliminate some loop) but Im lazy.

    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
        Q = int(input())
        for _ in range(Q):
            N = int(input())
            result = 0
            if 15 <= N <= 15*(10**8):
                if N%2 != 0:
                    half = N//2+1
                else:
                    half = N//2
                third = N//3+1
                for a in range(1,third):
                    for b in range(a,half):
                        c=(((a**2)+(b**2)+1)**(1/2))
                        check=c-int(c)
                        if check==0 and a+b+c<=N:
                            result+=1              
            else:
                result = 0
            fptr.write(str(result) + '\n')
        fptr.close()