Recently I am solving the problem name Palindromic Numbers, and I am not able to find out the idea that will optimise my code so that it can run under the given time-constraint, as editorial for the problem is also not given and my solution is giving TLE.

**Code Link:** https://www.codechef.com/viewsolution/26776713

Some of the codes which I have seen optimise on the basis of the following logic.

After iterating the loop till `sqrt(n)`

if there is no base in the range `[2,sqrt(n)]`

, then there is a loop as follows:

```
for(digit = n/(sqrt(n) + 1); digit >= 1; --digit) {
base = n/digit - 1;
if((n % digit == 0) && ((n / base) == (n % base)) && (digit < base)) {
printf("%d\n", base);
break;
}
}
```

**I am not able to understand the logic behind the above code? Could anyone help me out?**

@alei @anon55659401 @ssjgz @vijju123 @aryanc403