All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Sum of four squares (Posted on 2025-04-14) Difficulty: 3 of 5
There are infinitely many sets of positive integers A<B<C<D such that A^2+B^2, A^2+B^2+C^2, and A^2+B^2+C^2+D^2 are all squares. Find the value of A≤ 1500 which leads to the largest number of solutions.

No Solution Yet Submitted by K Sengupta    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Some Thoughts The code I used | Comment 4 of 5 |
gap = 1000
mA = 1500
mB = mA + gap
mC = mA + 2*gap
mD = mA + 3*gap
largest_possible = int((mA**2 + mB**2 + mC**2 + mD**2)**.5)
squares = [n**2 for n in range(largest_possible+1)]


sumsquares = {}
adict_ab = {}
adict_abc = {}
adict_abcd = {}
counts_ab = [0 for i in range(mA+1)]
counts_abc = [0 for i in range(mA+1)]
counts_abcd = [0 for i in range(mA+1)]

def sumsq(*args):
    if len(args) == 0:
        return 0
    elif len(args) == 1:
        return squares[args[0]]
    elif len(args) == 2:
        ans = args[0]**2 + args[1]**2
    else:
        thekey = ''
        for i,v in enumerate(args):
            if i == 0:
                thekey += str(v)
                continue
            if i == len(args) - 1:
                break
            thekey += ','+str(v)
        ans = sumsquares[thekey] + squares[args[-1]]
    return ans

for a in range(1, mA+1):
    for b in range(a+1, mB+1):
        mysum = sumsq(a,b)
        if mysum in squares:
            if a not in adict_ab:
                adict_ab[a] = [[a,b]]
                counts_ab[a] += 1
            else:
                adict_ab[a].append([a,b])
                counts_ab[a] += 1
            mykey = str(a)+','+str(b)
            sumsquares[mykey] = mysum

maxcountab = max(counts_ab)
indices_b = [i for i, x in enumerate(counts_ab) if x == maxcountab]
print('ab', indices_b, counts_ab[indices_b[0]])
print(sum(counts_ab))

        
for key, vals in adict_ab.items():
    a = key
    for val in vals:
        b = val[1]
        for c in range(b + 1, mC+1):
            mysum = sumsq(a,b,c)
            if mysum in squares:
                if a not in adict_abc:
                    adict_abc[a] = [[a,b,c]]
                    counts_abc[a] += 1
                else:
                    adict_abc[a].append([a,b,c])
                    counts_abc[a] += 1
                mykey = str(a)+','+str(b)+','+str(c)
                sumsquares[mykey] = mysum
            
maxcountabc = max(counts_abc)
indices_c = [i for i, x in enumerate(counts_abc) if x == maxcountabc]
print('abc', indices_c, counts_abc[indices_c[0]])
print(sum(counts_abc))   

for key, vals in adict_abc.items():
    a = key
    for val in vals:
        b = val[1]
        c = val[2]
        for d in range(c + 1, mD+1):
            mysum = sumsq(a,b,c,d)
            if mysum in squares:
                if a not in adict_abcd:
                    adict_abcd[a] = [[a,b,c,d]]
                    counts_abcd[a] += 1
                else:
                    adict_abcd[a].append([a,b,c,d])
                    counts_abcd[a] += 1
                mykey = str(a)+','+str(b)+','+str(c)+','+str(d)
                sumsquares[mykey] = mysum
            
maxcountabcd = max(counts_abcd)
indices_d = [i for i, x in enumerate(counts_abcd) if x == maxcountabcd]
print('abcd', indices_d, counts_abcd[indices_d[0]])
print(sum(counts_abcd))  

--------  output  -------(edited to add the number found)
ab [240, 420, 840]  (there was a tie each with 17 of them)
2673
abc [288]   (59 of them)
5185
abcd [288]  (121 of them)
7015

Edited on April 16, 2025, 1:01 pm
  Posted by Larry on 2025-04-16 12:58:45

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2025 by Animus Pactum Consulting. All rights reserved. Privacy Information