alright guys i know this does somewhat defeat the point of project euler but i just do not understand this. i found a bit of code that does give you the right answer but thats not what i want. what i want to know is why does it work. heres the code that i found. the main part im confused about is how does it check if a number is prime because the algorithm does putout non prime numbers so how does it know that those numbers cant be divided evenly into the factorof. also why does it divide factor of by the number when the number is a factor?
I doesn't 'somewhat' defeat the purpose of Project Euler, it totally defeats the purpose, spirit, intent and wishes of Project Euler and probably spoils it for other people too.
> how does it check if a number is prime
> why does it divide factor of by the number when the number is a factor?
as you see, it never checks that `num' is a prime number, however if `num' were composite, then the test at line 9 would fail.
Suppose that num = a*b, where `a' and `b' are primes.
If `num' divided evenly `factorOf', then `a' and `b' would also do it. But `a' and `b' would be try out first and remove themselves from `factorOf', so `num' would be no longer a divisor.
The same argument can be made for `a' and `b', so line 9 would only succeed if `num' is a prime number.