Count Shiprocket-Prime Numbers
At Shiprocket, optimizing our logistics and data processing often involves identifying special patterns in numerical data, which can range from parcel IDs to internal system metrics. To enhance our analytical capabilities, we've defined a new category of numbers: a "Shiprocket-Prime Number." These numbers hold unique properties that could be leveraged for data segmentation or cryptographic hashing. Your task is to identify and count these special numbers within a given range.
A number K is defined as a "Shiprocket-Prime Number" if the sum of its distinct prime factors is itself a prime number.
For example:
K = 10. Its distinct prime factors are 2 and 5. The sum is 2 + 5 = 7. Since 7 is a prime number, 10 is a Shiprocket-Prime Number.K = 12. Its distinct prime factors are 2 and 3. The sum is 2 + 3 = 5. Since 5 is a prime number, 12 is a Shiprocket-Prime Number.K = 30. Its distinct prime factors are 2, 3, and 5. The sum is 2 + 3 + 5 = 10. Since 10 is not a prime number, 30 is NOT a Shiprocket-Prime Number.Your task is to implement a function countShiprocketPrimes that takes an integer N and returns the total count of Shiprocket-Prime Numbers between 2 and N (inclusive).
N.
N: The upper bound (inclusive) for checking Shiprocket-Prime Numbers.N.P has only one distinct prime factor, which is P itself. The sum of its distinct prime factors is P. If P is prime, then P is a Shiprocket-Prime number.Examples
Example 1
Input:
N = 1
Output:
0
Note:
No numbers from 2 to 1 (inclusive) exist. So the count is 0.
Example 2
Input:
N = 10
Output:
9
Note:
Numbers 2, 3, 4, 5, 6, 7, 8, 9, 10 are Shiprocket-Prime:
Example 3
Input:
N = 20
Output:
17
Note:
Building on N=10 (9 Shiprocket-Primes):
Constraints
1 <= N <= 10^6N will always be a positive integer.Loading editor...