This question is, admittedly, somewhat poorly-posed (and for that reason I would be very receptive to anyone who can suggest ways to improve it).

I have recently been thinking about the following question:

Choose a positive integer $n$ and choose a randomly-generated function $f:\mathbb Z_n \to \mathbb Z_n$. What is the probability that this function corresponds to some polynomial $p \in \mathbb Z_n[x]$?

The question is at least somewhat natural to ask, insofar as if we work over $\mathbb R$, any set of $n$ points can be fit to some polynomial of degree at most $n-1$.

If $n$ happens to be prime, the answer is that the probability is $100 \%$. In more detail: for $n$ prime, any two distinct polynomials of degree $<n$ generate distinct functions, and therefore there are $n^n$ different polynomial functions. Since there are also $n^n$ functions from $\mathbb Z_n$ to itself, every function corresponds to a polynomial.

However, if $n$ is composite, the situation is dramatically different. In general the number of distinct polynomial functions is at most $n^k$, where $k$ is the sum of the prime factors of $n$ (with repetitions). For example if $n=80=2^4 \cdot 5$ then $k=2+2+2+2+5=13$ and there are at most $80^{13}$ different polynomial functions. That means the probability that a randomly-chosen function on $\mathbb Z_{80}$ corresponds to some polynomial is at most $\frac{80^{13}}{80^{80}}=80^{-67} $; that is, the probability is less than $1$ in $3 \times 10^{127}$.

To get a sense of how small that is, it's estimated that the number of atoms in the universe is between $10^{78}$ and $10^{82}$. So the polynomial functions on $\mathbb Z_{80}$ are much, much more scarce than a single atom among the entire universe.

However, if you decrease $n$ from $80$ to $79$ then the probability jumps to $100\%$. Use $n=81$ or $n=82$ and we are back to "rarer than a single atom in the entire universe" territory. But with $n=83$ we're back to $100 \%$.

I think the question is a fascinating one largely because of how dramatically the result depends on whether $n$ is prime or composite, and I am wondering if there are other, similarly dramatic instances of this.

So to be clear: the question I am asking here is not the one above (about polynomials over $\mathbb Z_n$), but rather the follow-up question inspired by it, i.e.

What are some other examples of questions in which the answer depends in rather dramatic form on whether an integer is prime or composite?

(And before anyone else says it: Yes, one obvious example is "What is the probability that $n$ has more than $1$ prime factor?", for which the answer is $0\%$ if $n$ is prime and $100\%$ if $n$ is composite. I'm interested in nontrivial instances of what I hope is a broad phenomenon.)

  • $\begingroup$ The polynomials $x^2+x$ and $0$ are distinct in $\mathbb Z_2$, but represent the same function. $\endgroup$ – Peter Jun 7 '18 at 20:26
  • 1
    $\begingroup$ @Peter Yes, I know. Note that I said that polynomials of degree $< n$ induce distinct functions. When $n$ is prime you begin to get repetitions at degree $n$. $\endgroup$ – mweiss Jun 7 '18 at 20:29
  • $\begingroup$ @Peter there are $2^2$ distinct polynomial functions on $\mathbb Z_2$, namely $0, 1, x$, and $x+1$. Any higher-degree polynomial is equivalent to one of these (in the sense that they induce the same function). $\endgroup$ – mweiss Jun 7 '18 at 20:31
  • $\begingroup$ The most basic question depending on whether $n$ is prime is : Is $\mathbb Z_n$ a field ? I am not sure which kind of such questions you are looking for. $\endgroup$ – Peter Jun 7 '18 at 20:35
  • 1
    $\begingroup$ @JyrkiLahtonen Thank you -- you may also be interested in this: mathoverflow.net/questions/160986/… $\endgroup$ – mweiss Jun 8 '18 at 5:41

I suppose that an example of such a computation consists in computing $\varphi(n)$, where $\varphi$ is Euler's totient function. If $n$ is prime, $\varphi(n)=n-1$. Otherwise, things get more complex.

  • $\begingroup$ There are plenty of similar cases: factoring, gcd, mod inverse, etc $\endgroup$ – qwr Jun 8 '18 at 18:07

I don't know if this is what you're looking for, but here's a shot at it.

There's a lot of probabilistic primality tests based on the fact that things drastically change when $n$ is composite, the easiest one probably being Fermat's primality test.

If $n$ is a prime number, then by Fermat's little theorem, $b^{n-1} \equiv 1 \mod n$ for every $b \in (\mathbb{Z} / n\mathbb{Z})^*$. A natural question to ask is whether or not the same thing happens for $n$ composite.

The answer is no most of the time. There are some numbers $n$ with the property that for all $b \in (\mathbb{Z} / n\mathbb{Z})^*$ where $b$ is coprime to $n$, $b^{n-1} \equiv 1 \mod n$. These are called Carmichael numbers. For example, there are 1547 Carmichael numbers below $10^8$. Most numbers are not Carmichael numbers.

If $n$ is not a Carmichael number, it is known that at least half of the $b \in (\mathbb{Z} / n\mathbb{Z})^*$ don't satisfy $b^{n-1} \equiv 1 \mod n$. Therefore if $n$ is composite and not a Carmichael number, and if you have a list $\{b_1,...,b_k\}$ of random integers $ \in (\mathbb{Z} / n\mathbb{Z})^*$ for which $b_i^{n-1} \equiv 1 \mod n$ for all $i$, the probability that this number is composite is at most $\frac{1}{2^k}$.

There are a lot of better (and more complicated) probabilistic primality tests based on the same concept which don't have the equivalent of ''Carmichael numbers'' and give a better probability that $n$ is prime. See the Solovay-Strassen and Miller-Rabin primality tests.

Hope this helps!


Pollard's $\rho$ algorithm can be used as an ingredient in an algorithm to factorise a number $n$. It iterates a process, generating a sequence $x_1, x_2,\dots$ continuing until it finds that the difference between two of the $x_i$ has a non-trivial factor in common with $n$. Usually such a factor $f$ is found within $O(\sqrt f)$ steps. Pollard's $\rho$ has a weakness, though: if $n$ is prime, the algorithm has no way to indicate this fact. Each step has a chance of $O(1/\sqrt n)$ of finding that two of the $x_i$ are equal modulo $n$ (i.e. the common factor is $n$), but this sometimes happens with composite $n$, so it is not proof that $n$ is prime. So here is a case where an algorithm works for composites but fails for primes.

(Pollard's $\rho$ is a great algorithm, but a factorisation algorithm which uses it needs to check $n$ for being prime first, and then feed $n$ to Pollard's $\rho$ only if it's composite.)


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.