Algorithm to find prime factoriztion in c