First try to get the algorithm right.You only want to divide by prime numbers.E.g. prime factors of 60 are 2,3 and 5.But you also need to know to what power a given prime needs to be raised: 60 = 2^2 * 3 * 5

First try to get the algorithm right.You only want to divide by prime numbers.E.g. prime factors of 60 are 2,3 and 5.But you also need to know to what power a given prime needs to be raised: 60 = 2^2 * 3 * 5

There are always several ways to approach problems such as this. Here is one solution for you.Note that the question posed chooses a number large enough (600851475143) to lie outside the range of a longint, so the following cannot be used for it without adaptation.

As I understood the original question, the product was supposed to give the original number back, not just the product of of the primes, but I may be wrong. […]

I think so, too.

I looked back into my study folder. Prime factorization itself was a programming assignment back then in CS1 (general CS class in first semester). The general idea was described in the problem set sheet, though. I translated (and slightly modified) what I'd programmed in java at that time: