TopCoder problem "ConstitutiveNumbers" used in TCCC06 Round 2C (Division I Level One)



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

0)
    
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
1)
    
1
101
Returns: 69
2)
    
1000
1030
Returns: 26
3)
    
7245723
7246428
Returns: 657
4)
    
1000000000
1000001000
Returns: 952

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6761

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10113&pm=6761

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , brett1479 , Cosmin.ro , Olexiy

Problem categories:

Math