My code gives time limit exceeded can any one have optimized way
You are given an integer NN. You are asked to find total number of integer pairs (A,B)(A,B) such that 1≤A,B≤N1≤A,B≤N A2+B2+gcd2(A,B)+lcm2(A,B)=NA2+B2+gcd2(A,B)+lcm2(A,B)=N. Note that gcd2(A,B)gcd2(A,B) and lcm2(A,B)lcm2(A,B) denote the square of gcd and the square of lcm of numbers AA and BB respectively. Input Format The first line of input contains a single integer TT, denoting the number of test cases. The description of TT test cases follows. The only line of each test case contains an integer NN. Output Format For each test case, output in a single line, number of valid pairs (A,B)(A,B). Constraints 1≤T≤1051≤T≤105 4≤N≤10104≤N≤1010 Sum of NN over all test cases does not exceed 10101010. Sample Input 1 3 4 10 20 Sample Output 1 1 2 2 Explanation Test case 1: The only valid pair is (1,1)(1,1). Here: 1≤1≤41≤1≤4. 12+12+gcd2(1,1)+lcm2(1,1)=1+1+1+1=412+12+gcd2(1,1)+lcm2(1,1)=1+1+1+1=4. Test case 2: Only 22 pairs are possible. These are: (1,2)(1,2) and (2,1)(2,1). https://code.sololearn