F - CNTFAC.py
Your task is to write a function count_factors(n)
that counts the total number of factors of a given integer n
. A factor of a number is a number that divides n
exactly, without leaving a remainder.
The factors of a number range from 1 to the number itself.
NOTE: avoid to divide by ZERO.
Input: An integer n
.
Output: Return the total number of factors of n
.
Example 1:
Input: n = 6
Return: 4
Explanation: The factors of 6 are 1, 2, 3, and 6, so the total number of factors is 4.
Example 2:
Input: n = 12
Return: 6
Explanation: The factors of 12 are 1, 2, 3, 4, 6, and 12, so the total number of factors is 6.
Example 3:
Input: n = 7
Return: 2
Explanation: The factors of 7 are 1 and 7, so the total number of factors is 2.
Example 4:
Input: n = 1
Return: 1
Explanation: The only factor of 1 is 1 itself, so the total number of factors is 1.