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

Home > Numbers
Sum of 2 Squares (Posted on 2024-04-14) Difficulty: 3 of 5
Let A and B be two different squares of positive integers, A < B, such that the set of base ten digits of A is the same as the set of base ten digits of B.

Find the smallest and largest value of A+B, such that A+B consists of 10 distinct digits.

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Computer Solution | Comment 1 of 3
B must be no larger than 9876543210;
so √B must be no larger than 99380

smallest and largest 
  A + B                  A                  B
1023498576 = 389667600 + 633830976
9876241305 = 68112009 + 9808129296

--------------
from itertools import combinations
dict1 = {}
for n in range(1, 99381):
    s = n**2
    ss = ''.join(sorted((set(str(s)))))
    if ss not in dict1:
        dict1[ss] = [s]
    else:
        dict1[ss].append(s)

dict2 = {}
for akey, alist in dict1.items():
    if len(alist) < 2:
        continue
    sortlist = sorted(alist)
    dict2[akey] = sortlist

solsDict = {}
for akey, alist in dict2.items():
    n_in_list = len(alist)
    for comb in combinations(alist,2):
        AplusB = sum(comb)
        strsum = str(AplusB)
        if len(strsum) != 10:
            continue
        if len(set(strsum)) != 10:
            continue
        if AplusB not in solsDict:
            solsDict[AplusB] = [[comb[0], comb[1]]]
        else:
            solsDict[AplusB].append([comb[0], comb[1]])

sums = sorted(solsDict.keys())

print(sums[0], solsDict[sums[0]])
print(sums[-1], solsDict[sums[-1]])

  Posted by Larry on 2024-04-14 10:05:40
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 (5)
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