You're looking to perform prime factorisation of integers, search the Web for more information.
A simplistic algorithm would be to use an existing list of primes up to the square root of the integer.
Iterate over this list, dividing the integer and setting the integer to be the quotient obtained whenever division may be performed perfectly.
Once a remainder will be obtained, move to the next prime in the list.
Once the list is exhausted, whatever primes used in perfect division and the final value of the integer are the prime factors.