Given an integer N, the task is to find the sum of exponents of prime factors of numbers 1 to N.
Input: N = 4
Numbers up to 4 are 1, 2, 3, 4 where
The exponent of 1 in the prime factorization of 1 is 0 (20),
For 2 it is 1 (21),
For 3 it is 1 (31), and
For 4 it is 2 (22).
The sum of the exponent of prime factors of each number up to 4 is 0 + 1 + 1 + 2 = 4.
Input: N = 10
sum of the exponent of prime factors of each number up to 10 is 15.
Approach: The idea is to use the concept of Prime factors and their powers. Below are the steps:
- Iterate for each number from 2 to N and for each number do the following:
- find the power of prime factors for each number N.
- Find the summation of each power in the above steps
- Print the summation of all the powers of prime factors of N and print the sum.
Below is the implementation of the above approach:
Time Complexity: O(N*log2N)
Auxiliary Space: O(N)
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.
- Find prime factors of Array elements whose sum of exponents is divisible by K
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Check if a number exists having exactly N factors and K prime factors
- Maximum number of prime factors a number can have with exactly x factors
- Find number of factors of N when location of its two factors whose product is N is given
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- K-Primes (Numbers with k prime factors) in a range
- Count numbers from range whose prime factors are only 2 and 3
- Number of distinct prime factors of first n natural numbers
- Common prime factors of two numbers
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Count common prime factors of two numbers
- Count numbers from range whose prime factors are only 2 and 3 using Arrays | Set 2
- Sum of Factors of a Number using Prime Factorization
- Sum of element whose prime factors are present in array
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Find and Count total factors of co-prime A or B in a given range 1 to N
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.