d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Efficient Divisor Algorithm?
Add Reply New Topic New Poll
Member
Posts: 2,769
Joined: Dec 24 2009
Gold: 14.00
Apr 12 2013 06:54pm
Does anyone have a good theorem to find the amount of factors in a number? For example, there are 9 factors in 100
I can't really think of a better way to search for amount of factors in n:

pseudocode:
divide n by all numbers 2 to sqrt(n) to see if any are integers
double the amount, add 2, subtract 1 if sqrt(n) is an integer

e.g: for 100
divide by 2,3,4,5,6,7,8,9,10, in the results there are 4 integers, and sqrt is an integer
4 x 2 + 2 - 1 = 9 factors in 100

Is this method frowned upon by programmers? Or at least acceptable?

This post was edited by Foxic on Apr 12 2013 06:56pm
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Apr 12 2013 09:02pm
there are "better" ways but they are not near as simple.
http://en.wikipedia.org/wiki/General_number_field_sieve
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll