TopcoderArchiveVisit Topcoder
Archive22 Aug 2006
TCCC06 Round 2C

ConstitutiveNumbers

Problem statement, definition, constraints, and public examples.

Problem Statement

Let's call a number constitutive if it can be expressed as a sum of three or more successive positive integers. For example, 14 is a constitutive number because 14 = 2+3+4+5, but 13 is not a constitutive number.

You will be given two ints A and B. Return the number of constitutive numbers between A and B, inclusive.

Definition

Class:
ConstitutiveNumbers
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int A, int B)
(be sure your method is public)

Constraints

  • A will be between 1 and 1,000,000,000, inclusive.
  • B will be between A and A + 1000, inclusive.

Examples

  1. 1
    15
    Returns: 6
    The first 6 constitutive numbers are: 6 = 1 + 2 + 3 9 = 2 + 3 + 4 10 = 1 + 2 + 3 + 4 12 = 3 + 4 + 5 14 = 2 + 3 + 4 + 5 15 = 4 + 5 + 6
  2. 1
    101
    Returns: 69
  3. 1000
    1030
    Returns: 26
  4. 7245723
    7246428
    Returns: 657
  5. 1000000000
    1000001000
    Returns: 952
Back to all problems