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

Home > Just Math
Consecutive Conclusion (Posted on 2014-09-30) Difficulty: 3 of 5
Determine the maximum possible value of N for which 311 is expressible as the sum of N consecutive positive integers.

No Solution Yet Submitted by K Sengupta    
Rating: 3.0000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Solution Comment 9 of 9 |
The sum of N consecutive integers, where the smallest one is "a" is given by:
(a - 1/2)N + N^2/2 = target = 3^11 in our problem.

I made a series of small functions in Python solving for target, a, and N in terms of the other two.
Although a is generally an integer, the function that calculates 'a' doesn't assume that.  It calculates an exact value for a(N,target), which for most values of N and target will not be an integer.
The program then starts at the largest possible value for N, then decrements by 1.  It then checks to see if the calculated value for a is an integer, and if so, prints it out.

The maximum value for N is then 486, with the first term in the series, a, equal to 122.

Note that if the word "positive" were eliminated from the stipulations:
N = 354,294 with a starting integer of (1 - 3^11) = -177,146

---- Python code follows ----
target = 3**11
def ceiling(x):
    return int((-x) // 1 * -1)

def sumConsec(a,N):
    """  sum integers a + (a+1) + ... + (a+N-1)  """
    return ((a-.5)*N + N*N/2)

def upper_bound_of_N(a, target=3**11):
    return ceiling( .5-a + ( a*a - a +.25 + 2*(target) )**.5 )

def calc_real_a(N, target=3**11):
    return .5 + (target)/N - N/2

print ( ' N ', ' a ')
for i in range(upper_bound_of_N(1),0,-1):
    if calc_real_a(i) == round(calc_real_a(i)):
        print(i, int(calc_real_a(i)) )

output:
 N   a 
486 122
243 608
162 1013
81 2147
54 3254
27 6548
18 9833
9 19679
6 29522
3 59048
2 88573
1 177147

  Posted by Larry on 2021-03-13 14:15:36
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 (12)
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