Problem 85
Number of Divisors
Easy · 10 pts · Math, Number Theory
Problem
You are given a positive integer N. Print how many positive integers divide N exactly, including 1 and N itself. Divisors come in pairs: if d divides N, so does N / d. So check every d from 1 while d × d <= N, and count 2 for each divisor found (d and N / d), or just 1 when d × d = N. For N up to 10^12, that is at most 10^6 checks. 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 divisors of N.
Constraints
1 <= N <= 1000000000000
Example input
12
Example output
6
Explanation
The divisors of 12 are 1, 2, 3, 4, 6 and 12. They pair up as (1, 12), (2, 6) and (3, 4), giving 6 divisors.