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