My hope is that this question is "trivial," but it is outside my knowledge base, so I'd appreciate some advice.

Given positive integers $m$ and $n$, find the least prime $p$ such that $p-1 = mnk$ for some $k \geq 1$.

For what I am trying to do, I need an explicit algorithm to find $p$, as opposed to an approximation. Is there a best one known? What is the upper bound on how much larger $p$ might be than $mn$? I am happy to assume that $m$ and $n$ are "sufficiently large" for the algorithm to have nice properties, if that helps.

Thank you. Hopefully the answer is obvious to everyone but me. :-)

  • 1
    $\begingroup$ When you write "for $k\ge1$", do you mean "for some $k\ge1$" or "for every $k\ge1$" ?:-( $\endgroup$ Oct 4 '11 at 3:11
  • $\begingroup$ @Chandan Singh Dalawat: I mean some $k$, in fact the smallest possible $k$. Now edited. $\endgroup$ Oct 4 '11 at 15:24

Firstly, I don't understand the point of having both $m$ and $n.$ Since only their product appears, call it $k.$ You are then trying to find the smallest prime congruent to $1$ modulo $k.$ The bound for such is a highly nontrivial matter, see (eg)


EDIT It is believed that you don't have to examine more than $\log^2 k$ multiples to find the first prime in a progression of your type.

  • 2
    $\begingroup$ The question asks for an algorithm. The algorithm will be to test all numbers of the form $mns+1$, for $s=1,2,\ldots$ for primality, using e.g., AKS (or something faster and probabilistic like Miller-Rabin). I don't think there is anything else you can do, as there are no simple ways of generating primes. The running time of this algorithm depends on the smallest prime that you meet and for that see Igor's answer. $\endgroup$ Oct 3 '11 at 17:56
  • $\begingroup$ @Felipe: Yes, thank you. I meant (implicitly) that you should test all the numbers until the bound, but it is much better to be explicit. (although the OP does also ask for the bound explicitly) I suppose that theoretically there could be a better algorithm then testing all the multiples, but I am pretty sure no one knows what it is. $\endgroup$
    – Igor Rivin
    Oct 3 '11 at 18:08
  • $\begingroup$ It might help to do some pre-sieving first, Eratostenes-like. Eg, if mn is odd there is no point in testing the odd multiples of mn; and make similar considerations for all other 'small' primes. $\endgroup$
    – user9072
    Oct 3 '11 at 18:22
  • $\begingroup$ @quid: true, but for any "reasonable" value of $k = mn,$ $\log^2 k$ is quite small (I suppose where reasonable means: small enough so you can test for primality). $\endgroup$
    – Igor Rivin
    Oct 3 '11 at 18:27
  • 1
    $\begingroup$ @quid: the $\log q^2$ is apparently a heuristic estimate due to Wagstaff. And you do have a good point about sieving: sieving wants to find many primes, here you are looking for one, so it might or might not help, depending on various subtleties... $\endgroup$
    – Igor Rivin
    Oct 3 '11 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.