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

Home > Numbers > Sequences
Consecutive in 2013 (Posted on 2013-01-07) Difficulty: 3 of 5
Determine all possible sequences of consecutive integers whose sum is precisely 2013.

No Solution Yet Submitted by K Sengupta    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Two computer methods. | Comment 2 of 5 |

In the following, a is the first term of the sequence and b is the last.

A program could just do the counting, advancing b by 1 and eventually advancing a to bring the total down as needed:

DEFDBL A-Z
CLS
a = 0: b = 1: tot = 1
WHILE b <= 2013
  b = b + 1
  tot = tot + b
  WHILE tot > 2013
    tot = tot - a
    a = a + 1
  WEND
  IF tot = 2013 THEN
    PRINT a; b, -a + 1; b
  END IF
WEND

finding the following pairs of starting and ending values:

 3  63        -2  63
 45  77       -44  77
 81  102      -80  102
 178  188     -177  188
 333  338     -332  338
 670  672     -669  672
 1006  1007   -1005  1007
 2013  2013   -2012  2013

Two pairs are listed on each line, the second pair accounting for the self-cancelling sequence from -(a-1) to (a-1) that can be prepended any strictly positive sequence.

This list contains 16 sequences, but if 2013 fails to qualify as a "sequence" there are still 15 sequences remaining, including that from -2012 to 2013.

Alternatively we could use a formula for the sum of a given sequence:

2012 = ((a+b)/2) * (b - a + 1)

Then varying b we could solve for a. The quadratic solves to:

a = (1 +/- sqrt(1 + 4*(b^2 + b -4026))) / 2

which is the basis for the following:

DEFDBL A-Z
FOR b = 1 TO 2013
  discr = 1 + 4 * (b * b + b - 4026)
  IF discr >= 0 THEN
    a = (1 + SQR(discr)) / 2
    approx = INT(a + .5)
    IF ABS(a - approx) < .0000001 THEN
      PRINT a; b
    END IF
    a = (1 - SQR(discr)) / 2
    approx = INT(a + .5)
    IF ABS(a - approx) < .0000001 THEN
      PRINT a; b
    END IF
  END IF
NEXT b

finding:

 3  63
-2  63
 45  77
-44  77
 81  102
-80  102
 178  188
-177  188
 333  338
-332  338
 670  672
-669  672
 1006  1007
-1005  1007
 2013  2013
-2012  2013

where the dual solutions of the quadratic account for the self-cancelling prepending of the sequences beginning in the negative values.


  Posted by Charlie on 2013-01-07 12:40:24
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 (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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