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.

Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official.
×

# | User | Rating |
---|---|---|

1 | tourist | 3372 |

2 | Radewoosh | 3353 |

3 | OO0OOO00O0OOO0O0…O | 3264 |

4 | V--o_o--V | 3247 |

5 | scott_wu | 3168 |

6 | Benq | 3154 |

7 | mnbvmar | 3143 |

8 | Petr | 3139 |

8 | ksun48 | 3139 |

10 | LHiC | 3118 |

# | User | Contrib. |
---|---|---|

1 | Radewoosh | 195 |

2 | Errichto | 175 |

3 | rng_58 | 159 |

4 | Ashishgup | 157 |

5 | neal | 156 |

6 | tourist | 154 |

7 | PikMike | 151 |

8 | Petr | 150 |

8 | Um_nik | 150 |

10 | Swistakk | 147 |

10 | kostka | 147 |

10 | Vovuh | 147 |

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.

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/10/2018 02:09:54 (d1).

Desktop version, switch to mobile version.

Supported by

User lists

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, fork≥ 2. Note thatk< 13 https://oeis.org/A002110. You would also have to check isnis prime.If there is only one query, you can find all primes in [2, 10

^{7}], find the smallest prime that dividesNand check the product easily. Be careful whenNis a prime number.