Given a non-negative integer n. The problem is to find the sum of the largest prime factor of each number less than equal to n.
Input : n = 10 Output : 32 Largest prime factor of each number Prime factor of 2 = 2 Prime factor of 3 = 3 Prime factor of 4 = 2 Prime factor of 5 = 5 Prime factor of 6 = 3 Prime factor of 7 = 7 Prime factor of 8 = 2 Prime factor of 9 = 3 Prime factor of 10 = 5 Sum = (2+3+2+5+3+7+2+3+5) = 32 Input : n = 12 Output : 46
sumOfLargePrimeFactor(n) Declare prime[n+1] and initialize all value to 0 Initialize sum = 0 max = n / 2 for p = 2 to max if prime[p] == 0 then i = p*2 while i <= n prime[i] = p i = i + p for p = 2 to n if prime[p] then sum = sum + prime[p] else sum = sum + p return sum
Sum = 46
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.
- Largest number less than N whose each digit is prime number
- Find largest factor of N such that N/F is less than K
- Count all the numbers less than 10^6 whose minimum prime factor is N
- Find Largest Special Prime which is less than or equal to a given number
- Largest number less than N with digit sum greater than the digit sum of N
- Number of triplets such that each value is less than N and each pair sum is a multiple of K
- Largest subset having with sum less than equal to sum of respective indices
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Largest number with maximum trailing nines which is less than N and greater than N-D
- Sum of Semi-Prime Numbers less than or equal to N
- Find largest prime factor of a number
- Largest number less than or equal to N/2 which is coprime to N
- Largest number less than or equal to Z that leaves a remainder X when divided by Y
- Find unique pairs such that each element is less than or equal to N
- Print all Semi-Prime Numbers less than or equal to N
- Highest and Smallest power of K less than and greater than equal to N respectively
- Count pairs with sum as a prime number and less than n
- Find sum of a number and its maximum prime factor
- Sum of Maximum and Minimum prime factor of every number in the Array
- Sum of elements in 1st array such that number of elements less than or equal to them in 2nd array is maximum
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar