Project Euler #142: Perfect Square Collection

Sort by

recency

|

12 Discussions

|

  • + 0 comments

    I am bit confused with the problem statements.

  • + 0 comments

    Passed all test cases except #7 and #8.. Anybody have any tips about why this might be? To me my algorithm works when N>=3000, but apparently not?

    It's not a timeout issue as I'm returning answers fast.

  • + 1 comment

    error: no suitable method found for valueOf(BigInteger)

    for (BigInteger x =BigInteger.valueOf(1234567890);x.compareTo(BigInteger.ZERO) > 0;x=x.subtract(BigInteger.ONE)) { for (BigInteger y =BigInteger.valueOf(x);y.compareTo(BigInteger.ZERO) > 0;y = y.subtract(BigInteger.ONE)) { for (BigInteger z = BigInteger.valueOf(y); z.compareTo(BigInteger.ZERO) > 0; z = z.subtract(BigInteger.ONE))

    pls help!!!

  • + 1 comment

    can we use bisection search to find the numbers ?

  • + 0 comments

    Here is my answer to the question. Arrived at this solution after looking at Euler's solution(https://sites.google.com/site/tpiezas/0020). But it is not running due to timeout problem :(

    import math

    from itertools import combinations

    def perfect_square(n):

    res = int(math.sqrt(n))
    
    return res*res == n
    

    def check_perfect(list):

    p, q, r, s = list    
    
    if perfect_square( (p*p-q*q)*(r*r-s*s) ):    
    
        a = p*r + q*s    
        b = p*s - q*r
        c = p*r - q*s
        d = p*s - q*r
        x = int((a*a + b*b)/2)        
        y = int((a*a - b*b)/2)
        z = int((c*c - d*d)/2)
        if(x>y and y>z):
            print(p,q,r,s,x,y,z)
    

    list = []

    for i in range(1,int(math.pow(10,12)+1)):

    if(perfect_square(i)):
    
        list.append(i)
    

    for i in combinations(list, 4):

    check_perfect(i)