I am getting TLE on the codeforces problem Two Divisors from the recent educational contest. Link to the problem:- https://mirror.codeforces.com/problemset/problem/1366/D. Link to my submission:- https://mirror.codeforces.com/contest/1366/submission/83516292. Please suggest ways to optimize it.
Thank you.