Consecutive Sum
Time limit5sMemory limit256 MB
Given q, count how many p make the sum of p consecutive integers equal the sum of the next q consecutive positive integers. Handle up to 2000 queries with q below 10^14.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Binary search, Combinatorics
- Solved
- No attempts yet
Problem
There are cases where the sum of consecutive integers () equals the sum of the consecutive positive integers that immediately follow them.
For example, , so and ; and , so and .
Given , write a program that counts how many values of satisfy this condition.
Input
The input consists of several test cases. Each test case is a single line containing one integer . is a positive integer less than .
The last line of the input contains a single , which is not processed. The number of test cases does not exceed .
Output
For each test case, print the number of values of that satisfy the condition, one per line.