Divisors

From Algorithmist
Jump to navigation Jump to search

A divisor is a number that divides a larger number. In programming problems, you may be requested to count or sum divisors.

Obtaining divisors[edit]

First, you need a list of prime factors of a given number. For example, 1575 has prime factors 3, 5, and 7.

Next, determine how many times a given factor can be factored into the number. In this example, 1575=32 * 52 * 7

This generally fits the patter similar to n = ax * by * cz. More or less factors may appear, depending on the number. You can get each divisor of a number by lowering any of these powers downward (as far as 0).

In the pattern above, the total number of divisors is (x+1)*(y+1)*(z+1).

Sum of Divisors[edit]

Implementation (C++) and Rules: http://www.shawonruet.com/2016/07/finding-sum-of-divisors.html

Number of Divisors[edit]

Implementation (C++) and Rules: http://www.shawonruet.com/2016/07/finding-number-of-divisors.html

External links[edit]