How to determine whether a number is a product of consecutive primes? The number can be at max 10^14. Any hints is really appreciated.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
8 | Dominater069 | 154 |
8 | nor | 154 |
How to determine whether a number is a product of consecutive primes? The number can be at max 10^14. Any hints is really appreciated.
Name |
---|
If the number is a product of 2 consecutive primes then how large can those primes be?
What is the maximum number of consecutive primes you can multiply so that the product is within 10^14?
Assume p and q are the required consecutive primes which satisfy p*q=n. Since p is not equal to q, p has to be less than √n and q has to be greater than √n. Also, for them to be consecutive, p has to be the largest prime number less than √n and q has to be the smallest prime number greater than √n.
Edit: The above solution checks for 2 consecutive primes. The above solution extended for k primes is explained here.
If you are only looking for 2 consecutive primes, then find the largest prime and the smallest prime and check if their product is equal to n. You might be able to make a similar idea work for any number of consecutive primes, though it seems tricky.
If it's a variable number of consecutive primes, you can try to binary search for a k-size subarray of primes that matches, for k ≥ 2. Note that k < 13 https://oeis.org/A002110. You would also have to check is n is prime.
If there is only one query, you can find all primes in [2, 107], find the smallest prime that divides N and check the product easily. Be careful when N is a prime number.