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

Home > Numbers
3 and 3 and... (Posted on 2020-12-13) Difficulty: 2 of 5
This number is, inter alia, a sum of 3 consecutive primes and can also be represented as a sum of 3 non-zero squares (not necessarily distinct) in 8 different ways.

Find the smallest number fitting the above description.

What else can be added re this number?

No Solution Yet Submitted by Ady TZIDON    
Rating: 3.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution re: computer solution (Charlie's program had no bugs) | Comment 2 of 3 |
(In reply to computer solution -- hope there are no bugs by Charlie)

I got the same result as Charlie

689 = sum of (227, 229, 233)
[(4, 9, 676),
(4, 324, 361),
(9, 196, 484),
(16, 144, 529),
(36, 169, 484),
(49, 64, 576),
(64, 225, 400),
(144, 256, 289),
(169, 196, 324)]

def isprime(n):
    '''check if integer n is a prime'''
    n = abs(int(n))
    if n < 2:
        return False
    if n == 2:
        return True    
    if not n & 1:
        return False
    for x in range(3, int(n**0.5)+1, 2):
        if n % x == 0:
            return False
    return True

def prime_nth(n):
    """ output the n-th prime """
    global p
    if 'p' not in globals():
        p = {1:2, 2:3, 3:5, 4:7}
    if n in p:
        return p[n]
    else:
        keymax = max(p, key=p.get)
        for i in range(keymax+1, n+1):
            keymax = max(p, key=p.get)
            testNum = p[keymax] +2
            while isprime(testNum) == False:
                testNum += 2
            p[i] = testNum
        return p[n]

ansList = []   # will contain sorted list of 3-prime sums with 8 ways
squares8ways = []   # on second pass compile list of triplets of squares
                    # get smallest, then edit to un-comment 3 lines below

big = 1000
sq_limit = int(prime_nth(big) ** .5)

sqDict = {}
for i in range(1,sq_limit+2):    #  Make dictionary of squares
    sqDict[i] = i*i

sumList = []   # list of sums of 3 consecutive primes
for i in range(1,big-2):
    x = p[i]+p[i+1]+p[i+2]
    sumList.append(x)

sumDict = {}   # Dictionary of sums of 3 primes and how many occurences
for i,val in enumerate(sumList):
    sumDict[val] = 0

from itertools import combinations_with_replacement
for triplet in combinations_with_replacement(list(sqDict.values()),3):
    sumOf3 = triplet[0]+triplet[1]+triplet[2]
#    if sumOf3 == 689:                 #un-comment 2nd pass
#        squares8ways.append(triplet)  #un-comment 2nd pass
    if sumOf3 in sumList:
        sumDict[sumOf3] += 1
        if sumDict[sumOf3] == 8:
            ansList.append(sumOf3)
            
print(sorted(ansList))
#print(squares8ways)                   #un-comment 2nd pass

  Posted by Larry on 2020-12-13 15:21:40
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
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 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information