Sum of LCM
You are given an integer ‘N’ , calculate and print the sum of :
LCM(1,N) + LCM(2,N) + .. + LCM(N,N)
where LCM(i,n) denotes the Least Common Multiple of the integers ‘i’ and ‘N’.
Input Format:
The first line of input contains a single integer T representing the number of test cases.
The first line of each test case contains a single integer ‘N’ representing the number of times we have to take LCM sum.
Output Format :
For each test case, return the required sum in a new line
Note :
You don’t need to print anything. It has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 50
1 <= N <= 10^4
Where ‘T’ is the number of test cases, and ‘N’ is the given integer
Time Limit:1sec
CodingNinjas
author
2y
Brute force approach
Using the mathematical formula, A*B = LCM(A,B) * GCD(A,B) where ‘A’ and ‘B’ are the two integers, and GCD(A,B) denotes the Greatest common divisor of ‘A’ and ‘B’.
For example, supp...read more
CodingNinjas
author
2y
optimized approach
We will use Euler Totient function to solve this problem,
Euler’s Totient function Φ (n) for an input ‘n’ is the count of numbers in {1, 2, 3, …, n} that are relatively prime to n, i....read more
Help your peers!
Add answer anonymously...
Top Google Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Google Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app