11

Basically, the problem is: For a set $S$ of positive numbers, find a minimal number $d$ that is not a divisor of any element of $S$, i.e. $\forall x \in S,\ d \nmid x$.

Denote $n = |S|$ and $C = \max(S) $. Consider the function $F(x) = $ the least prime number not dividing $x$. It is easy to see that $F(x) \leq \log x$. And for a set $S$, let $F(S) = $ the least prime that doesn't divide any element of $S$. We have an upper bound

$$F(S) \leq F(\operatorname{lcm}(S)) \leq F(C^n) \leq n \log C.$$

Therefore a simple brute-force algorithm, which enumerates all numbers from $1$ to $n \log C$ and checks if it doesn't divide any element of $S$, is polynomial and has time complexity $O(n^2 \log C)$.

The other way to solve the problem is to compute all factors for every element of $S$ and use them in brute-force algorithm to check if $x$ is an answer in $O(1)$ time. This algorithm has time complexity $O(n \cdot \min (\sqrt{C}, n \log C) + n \log C)$ and uses $O(n \log C)$ memory, because we don't need to compute and store factors greater than $n \log C$. For small $n$ and $C$ it performs better.

In detail, the algorithm consists of two parts:

  1. Construct a set $\hat{S}$ composed of all factors of all elements of $S$, i.e. $$\forall x \in S\ \forall f \le n \cdot \log C, \ (f \mid x \rightarrow f \in \hat{S})$$ This can be done in $O(n \cdot \min (\sqrt{C}, n \log C))$ time and $O(n \log C)$ memory. (Where does this come from? For any element of $S$, we can factor it using either trial factorization with all numbers up to $\sqrt{C}$ or all primes up to $n \log C$, whichever is smaller; thus each element of $S$ can be factored in time $O(\min (\sqrt{C}, n \log C))$ time.)

  2. Find minimal number $d \notin \hat{S}$. This step requires $O(|\hat{S}|) = O(n \log C)$ time, if checking whether $x \in \hat{S}$ can be done in $O(1)$ time.

I have two questions that I'm interested in:

  1. Is there a faster algorithm to solve the problem?
  2. For given $n$ and $C$, how can we construct a set $S$ with maximal least common non-divisor?
D.W.
  • 159,275
  • 20
  • 227
  • 470
SkyterX
  • 163
  • 5
  • By "precompute" i meant before starting brute-force algorithm. 2. Complexity of factoring is indeed subexponential, see the definiton of $C$.
  • – SkyterX Oct 16 '15 at 19:34
  • @D.W. on point 2, the complexity of factoring is subexponential on the length of the bitstring representing the number, but SkyterX correctly says that it is $O(\sqrt{C})$, that is, proportional to the square root of the size of the number. – Lieuwe Vinkhuijzen Oct 16 '15 at 22:52
  • @LieuweVinkhuijzen, That doesn't look right to me. The complexity of factoring using GNFS will be something like $O(\exp{1.9 (\log C)^{1/3} (\log \log C)^{2/3}})$, which is significantly less than $O(\sqrt{C})$. See https://en.wikipedia.org/wiki/Integer_factorization#Difficulty_and_complexity. – D.W. Oct 17 '15 at 00:23
  • The statement that the second method performs better "for small $n$ and $C$" isn't quite right. It performs better only if $n \gg \sqrt{C}/\log(C)$. Thus $n$ needs to be large for the second method to perform better (not small). – D.W. Oct 17 '15 at 02:07
  • @D.W. You're right, I wasn't aware of the complexity of the GNFS. – Lieuwe Vinkhuijzen Oct 17 '15 at 11:15