Hi there… I have been trying this problem since last night… Can someone point out why this code is giving TLE on one test set?

https://www.codechef.com/viewsolution/59389077

Problem Link: https://www.codechef.com/problems/MAGICMOD

Logic is same as given in editorial, I first subtract n*(n+1)/2 from sum of all elements and then check for all factors of the new sum if any of them satisfy the condition… for checking, I use a set to compare the permutation if a particular factor generates the permutation… so each factor takes O(N) time, which is well under constraints… still giving TLE.