Given a positive number N. The task is to find maximum sum of distinct numbers such that the LCM of all these numbers is equal to N.
Input : 2 Output : 3 The distinct numbers you can have are just 1 and 2 and their sum is equal to 3. Input : 5 Output : 6
As the LCM of all the numbers is N. So all the numbers must be the divisors of N and all the numbers are distinct so answer must be the sum of all the divisors of N. To find all the divisors efficiently refer to article https://www.geeksforgeeks.org/find-all-divisors-of-a-natural-number-set-2/
This article is contributed by Ayush Jha. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of LCM(1, n), LCM(2, n), LCM(3, n), ... , LCM(n, n)
- Maximum sum of distinct numbers with LCM as N
- Find two distinct numbers such that their LCM lies in given range
- Minimum replacement of pairs by their LCM required to reduce given array to its LCM
- Find three integers less than or equal to N such that their LCM is maximum
- Find two numbers with given sum and maximum possible LCM
- Number of distinct integers obtained by lcm(X, N)/X
- Find the pair (a, b) with minimum LCM such that their sum is equal to N
- Maximum LCM among all pairs (i, j) of first N natural numbers
- Count numbers whose maximum sum of distinct digit-sum is less than or equals M
- Minimum possible value of max(A, B) such that LCM(A, B) = C
- Number of pairs such that their HCF and LCM is equal
- Count of pairs upto N such whose LCM is not equal to their product for Q queries
- Number of ways to change the Array such that largest element is LCM of array
- Maximum length subarray with LCM equal to product
- Sum of M maximum distinct digit sum from 1 to N that are factors of K
- Split array into maximum subarrays such that every distinct element lies in a single subarray
- Print any pair of integers with sum of GCD and LCM equals to N
- Count of all possible pairs having sum of LCM and GCD equal to N
- Distinct powers of a number N such that the sum is equal to K