Connection Status:
Competition Arena > ConstitutiveNumbers
TCCC06 Sponsor 2 · 2006-08-22 · by Andrew_Lazarev · Math
Class Name: ConstitutiveNumbers
Return Type: int
Method Name: count
Arg Types: (int, int)
Problem Statement

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.

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

Submissions are judged against all 105 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ConstitutiveNumbers with a public method int count(int A, int B) · 105 test cases · 2 s / 256 MB per case

Submitting as anonymous