7

I would like to know if there's a quick way to check if a number is semiprime. By far all the links I have seen only tell either how to generate a semiprime or count the number of semiprimes or to factorize it... But I just want to check whether it is one or isn't.

  • There is no easy method. The best you can do is test if it is prime or not, then check for factors up to at most $n^{1/3}$ for divisibility. – Foo Barrigno Jul 01 '13 at 17:09
  • @FooBarrigno If you are dealing with semi primes, then you have to check for factors up to the square root of n (n^1/2). Checking factors to the cube root of n (n^1/3) will do you no good if one of the factors is above cube root of n – zerosofthezeta Jul 01 '13 at 17:40
  • 4
    @diophantine - The OP wasn't trying to find a factor of the semiprime, only identify whether or not the number was a semiprime or not. Checking up to the cube root is sufficient in that case - because it rules out any number with 3 or more prime factors. – Foo Barrigno Jul 01 '13 at 17:42
  • @FooBarrigno I might be mistaken, but semi prime refers to a number with ONLY two factors which are prime, so I don't see how you obtain the cube root of n. Could you please elaborate? – zerosofthezeta Jul 01 '13 at 18:50
  • @diophantine - If you do not find a factor below the cube root of n, then you know that the number can only have 2 factors, and thus is a semi prime. If you DO find a factor below the cube root of n, then you need to check whether or not $n/q$ is prime. – Foo Barrigno Jul 01 '13 at 19:05
  • Thanks i did it in cube root n.... – Kartik Khare Jul 02 '13 at 07:13

2 Answers2

5

For small numbers, the best method is to trial-divide by primes (or take the gcd with blocks of primes). If a prime factor is discovered, divide it out and test if the rest is prime or not. If no prime factor is found up to the cube root, it is semiprime if and only if it is not prime (assuming it is > 1). Usually the best order is trial dividing by the first hundred or so primes, checking if the number is itself prime, then finishing the trial division.

For large numbers, do a reasonable amount of trial division, check if the number is prime, run some ECM curves, then factor it completely (with SIQS or NFS, or perhaps even MPQS if the numbers are small enough). This is faster than trial division all the way up to the cube root.

The best way to find out what numbers are 'big' vs. 'small' is to implement both methods and test. As an order of magnitude, 1014 is probably the largest size where trial division outperforms ECM + MPQS.

It may be possible, for numbers of intermediate size, to use Strassen's algorithm (as improved by Costa & Harvey, building on Bostan, Gaudry, & Schost, themselves building on Chudnovsky & Chudnovsky's improvements on Strassen's original). Asymptotically, this takes time $O(n^{1/6}\log^{2+\varepsilon} n)$ compared to $O(n^{1/3}\log n)$ for trial division (using schoolbook division -- too small for Karatsuba) and $O(\exp(c(\log n)^{1/3}(\log\log n)^{2/3}))$ for the NFS. I haven't seen a practical implementation of this algorithm, so I can't speak to what its true breakpoints might be, but 1040 should be a rough upper bound.

Charles
  • 32,999
4

David Broadhurst came up with a provable semiprime back in 2005, based on some ideas from Don Reble and Phil Carmody.

From MathWorld's semiprime -- "In 2005, Don Reble showed how an elliptic pseudo-curve and the Goldwasser-Kilian ECPP theorem could generate a 1084-digit provable semiprime without a known factorization (Reble 2005)."

It's not quick. For quick, you need relative small, factorable numbers.

Charles
  • 32,999
Ed Pegg
  • 21,868
  • 1
    Do you know how Reble generated the certificate? I can't figure out how to do it without knowing the order of the elliptic curve, and I am starting to think that he generated $N$ as the product of two primes so that he would know the factorization. In general finding the order of an elliptic curve modulo $N$ requires factoring $N$, but maybe there is a way to generate elliptic curves of known order, or to generate them together with $N$. – qbt937 Sep 20 '20 at 05:16
  • I don't know, but he knows the factorization: "I have withheld one vital datum, namely a prime of size around N^(1/6). While this is not needed to prove the semiprimality of N, it enables rapid factorization of N." – Charles Sep 27 '24 at 19:48