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
- Find largest prime factor of a number
- Find Largest Special Prime which is less than or equal to a given number
- N-th prime factor of a given number
- k-th prime factor of a given number
- Largest factor of a given number which is a perfect square
- Find sum of a number and its maximum prime factor
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]
- Largest number with prime digits
- Largest number that divides x and is co-prime with y
- Prime Factor
- Largest number less than N whose each digit is prime number
- Queries for the smallest and the largest prime number of given digit
- Largest number not greater than N which can become prime after rearranging its digits
- Sum of largest divisible powers of p (a prime number) in a range
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