So I am a bit confused about how to find the prime divisors of a given number.
I figured I could start with 2 and go all the way up to sqrt(number).But now here is the problem, for big numbers is seems to work(or it doesn't, i can't be sure),but I am certain that is doesn't work for small numbers.
Ex:The divisors of 42 are:1 2 3 6 7 14 21 42 , but sqrt(42)=6.4 so it doesn't get to 7.
The code would look like this:
Your method is wrong. You need to go to sqrt(n) when you're looking for all divisors. Then if n % i == 0 you find two divisors: i and n/i. So if i can go up to 6 it will find 42/6 = 7.
Consider number 26 = 2*13. 13 is prime, but it is nowhere near sqrt(26) ~ 5.
What you need to do, is go from 2 to n and every time you find n % i == 0 ,do n = n/i.
Note that a single prime divisor may go several times.