Project Euler #224: Almost right-angled triangles II

Sort by

recency

|

20 Discussions

|

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

    am confused,i dont get the example pls provide the answers to a,b, and c for the example u gave "21". so far it got me only one 4,8 and 9 resectively

  • + 0 comments

    2 days of math and code, result: 25 :(

  • + 0 comments

    This code is Timed out for all the test cases except the test case 0.can any one explain me where i did wrong?

    include

    include

    include

    include

    int main() { long long int n,q,a,b,c,d=0; scanf("%lld",&q); while(q--) { scanf("%lld",&n); for(a=1;a<=n;a++) { for(b=a;b<=n;b++) { for(c=a;c<=n;c++) { if( pow(a,2)+pow(b,2) == pow(c,2)-1 ) { if(a+b+c<=n) d++; //printf("%lld %lld %lld \n",a,b,c); } } } } printf("%lld\n",d); }

    return 0;
    

    }

  • + 1 comment

    There is a timeout for all test cases except for test 0.