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.
- Maximum sum of distinct numbers with LCM as N
- Numbers less than N which are product of exactly two distinct prime numbers
- Numbers having Unique (or Distinct) digits
- Exactly n distinct prime factor numbers from a to b
- Find N distinct numbers whose bitwise Or is equal to K
- Check if all sub-numbers have distinct Digit product
- Print combinations of distinct numbers which add up to give sum N
- Count of N-digit numbers with all distinct digits
- Find two distinct prime numbers with given product
- Largest of two distinct numbers without using any conditional statements or operators
- Count of distinct remainders when N is divided by all the numbers from the range [1, N]
- Number of distinct prime factors of first n natural numbers
- Maximum value of division of two numbers in an Array
- Maximum possible Bitwise OR of the two numbers from the range [L, R]
- Maximum LCM among all pairs (i, j) of first N natural numbers