Answer the question
In order to leave comments, you need to log in
How to count the number of divisors?
How can you calculate the number of divisors when dividing a number by a number? C language
Answer the question
In order to leave comments, you need to log in
We put 1 in the accumulator. We sort through the
numbers from 2. If possible, then only simple ones, or 2 and odd ...
If our number x is divisible by the current number p, then we divide it, while it is dividing, we count how many times it was divided (which means x is divisible by p^n). Multiply the accumulator by n+1.
If we reach such a p that p^2 > x, then look: if x is not equal to 1, multiply the accumulator by 2.
For example:
x=5040, acc=1
p=2. x is divisible by 2^4. After dividing x=315, acc=5.
p=3. x is divisible by 3^2. After dividing x=35, acc=5*3=15.
p=5. x is divisible by 5^1, After dividing x=7, acc=15*2=30.
p=6. x < p^2, exit the loop
x!=1 => acc=30*2=60.
Answer: 60 divisors.
If it's too slow, learn fast factorization algorithms.
The algorithm is extremely simple:
We go from 1 to the root of the number (optimal solution) or to half the number (normal solution)
and check what the remainder of dividing the original number by the given one is. If the remainder is zero, then
increase the number of divisors by one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question