GCD Sum Problem Statement
Given an integer 'N', the task is to find the sum of the greatest common divisor (GCD) of all pairs (i, j) such that 1 <= i < j <= N.
Input:
T
(the number of test cases)
For each test case:N
(an integer)
Output:
An integer representing the sum of GCD of all pairs of numbers from 1 to N.
A new line for each test case.
Example:
Input:
T = 1
N = 3
Output:
3
Explanation:
For N = 3, the pairs are (1, 2), (1, 3), and (2, 3). The GCDs are 1, 1, and 1 respectively; sum is 3.
Constraints:
1 <= T <= 5
1 <= N <= 5000
Note:
You do not need to perform input/output operations as it has been handled. Implement the function and return the result.

AnswerBot
4mo
Calculate the sum of GCD of all pairs of numbers from 1 to N.
Iterate through all pairs of numbers from 1 to N and calculate GCD
Add all the calculated GCDs to get the final sum
Optimize the GCD calculat...read more
Help your peers!
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

