NUMFACT - Time limit exceed error

It gives a TLE when i use the function ‘prime’ to find the prime factorisation of the number.Can someone please tell me where i went wrong? Thanks in advance.
Here is the link to my code : http://ideone.com/kgzICq

Hi, Kindly post your query on the editorial page of the problem here: http://discuss.codechef.com/questions/15943/numfact-editorial

//