spoj-NFACTORFUl-TLE

hello guys,i was doing spoj N-FACTORFUL i think my approach is right but everytime i submit it…it shows tle can anyone tell me where i am lacking-My solution