Bug fixed...j should iterate from 1 instead of 2
Time limit exceeding ..Used mathematical algorithm