All problems

Problem 351

Sum of Consecutive Integers

Medium · 20 pts · Math, Number Theory

Problem

Count the ways to write N as a sum of one or more consecutive positive integers. For example, 9 = 9 = 4 + 5 = 2 + 3 + 4, so there are 3 ways. A sum of k consecutive numbers starting at a equals k·a + k(k-1)/2, so for each length k you can check whether a valid start exists; it turns out the answer equals the number of odd divisors of N. The numbers in this problem can be larger than a 32-bit int can hold (about 2.1 × 10^9), so use a 64-bit integer type: long long in C++, long in Java (Python needs nothing special).

Input

A single integer N.

Output

Print the number of ways.

Constraints

1 <= N <= 1000000000000

Example input

15

Example output

4

Explanation

15 can be written as 15, 7 + 8, 4 + 5 + 6 and 1 + 2 + 3 + 4 + 5, so there are 4 ways.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Sum of Primes up to N Next: Matrix Determinant