13

I want to determine prime numbers $p$ with this property $(P)$: $p\nmid 2^n+3^m,\forall n,m\in\mathbb{N}$. ($m,n$ are allowed to be zero)

I was able to find that primes $p$ with $p\equiv 23 (\text{mod}\: 24)$ have the desired property, as we have this equivalence regarding Legendre symbols: $$p\equiv 23 (\text{mod}\: 24)\iff -\left(\frac{-1}{p}\right)=\left(\frac{2}{p}\right)=\left(\frac{3}{p}\right)=1.$$ Indeed, if we assume that $p|2^n+3^m\Rightarrow 2^n\equiv-3^m (\text{mod} \: p)$. The left hand-side is a quadratic residue, whilst the right hand-side is not, hence the contradiction.

One can naturally ask about the converse:

Question: Must a prime $p$ satisfying $(P)$ have the form $p\equiv 23 (\text{mod}\: 24)$?

A prime $p$ which is not of the previous form, must satisfy $p\equiv 1,5,7,11,13,17,19 (\text{mod}\: 24)$. I checked the smallest primes, they don't satisfy $(P)$: $$2=2^0+3^0; 3=2^1+3^0; 5=2^1+3^1; 7=2^2+3^1; 11=2^3+3^1; 13=2^2+3^2;$$ $$17=2^4+3^0; 19=2^3+3^2; 29=2^1+3^3; 31=2^2+3^3; 37\cdot 7=2^8+3^1.$$ But still, I cannot find a pattern, and I don't know what to expect.


EDIT: Based on the code provided by @nocomment, I improved a bit the prime generator, up to $200000$, using the sieve of Eratosthenes:

N=200000
a=[0]*(N+1)#prime or not
prime=[2]#make the sieve first
for i in range(4,N+1,2):
    a[i]=1
for i in range(3,N+1,2):
    if a[i]==0:
        for j in range(i*i,N+1,i):
            a[j]=1

for i in range(3,N+1,2): if a[i]==0: prime.append(i) #%%

def powers_modulo(base, mod): powers = set() power = 1 while power not in powers: powers.add(power) power = power * base % mod return powers

def P(p): pow2 = powers_modulo(2, p) pow3 = powers_modulo(3, p) for a in pow2: if -a % p in pow3: return False return True

for p in prime: P_ = P(p) if (p % 24 == 23) != P_: print(p, p % 24, P_)

The result is the following (took me some $4$ minutes). So we generate only prime solutions that are not $23$ mod $24$. All of them, up to $200000$, are $1$ mod $24$.

601 1 True
4297 1 True
6553 1 True
11113 1 True
12073 1 True
12409 1 True
12457 1 True
15241 1 True
16633 1 True
17209 1 True
17881 1 True
20809 1 True
31033 1 True
33721 1 True
36529 1 True
40153 1 True
47017 1 True
47497 1 True
47881 1 True
49369 1 True
49417 1 True
50377 1 True
55609 1 True
56713 1 True
57649 1 True
58153 1 True
58921 1 True
59281 1 True
63241 1 True
63577 1 True
65929 1 True
66841 1 True
67033 1 True
70921 1 True
71761 1 True
72937 1 True
73417 1 True
77977 1 True
78697 1 True
83449 1 True
86857 1 True
88177 1 True
88681 1 True
91033 1 True
91129 1 True
97369 1 True
101737 1 True
104233 1 True
104953 1 True
105673 1 True
106681 1 True
107089 1 True
108649 1 True
108793 1 True
110569 1 True
114217 1 True
114889 1 True
121369 1 True
121993 1 True
130681 1 True
132409 1 True
132697 1 True
133321 1 True
139369 1 True
142057 1 True
148921 1 True
151057 1 True
152041 1 True
153529 1 True
155569 1 True
159097 1 True
161641 1 True
165721 1 True
167593 1 True
168409 1 True
172009 1 True
172681 1 True
172969 1 True
174121 1 True
178441 1 True
182041 1 True
182089 1 True
182929 1 True
184153 1 True
187513 1 True
189961 1 True
190633 1 True
191497 1 True
196681 1 True

Based on this numerical evidence, maybe one can theoretically prove what all the prime solutions are. Or that other residues (except $1$ and $23$) cannot appear.


EDIT $2$: Thanks to @Einar Rødland, we were able to find a faster test. Indeed, a prime $p$ has property $(P)$ iff $2^q\equiv 3^q\equiv 1( \text{mod} \:p)$, where $p−1=2^rq,2\nmid q$. The improved Python code is the following, it generates (in less than a minute) $2946$ prime numbers up to $10^7$, exactly as Einar did, all of them being $1$ mod $24$:

N=10000000
a=[0]*(N+1)#prime or not
prime=[2]#make the sieve first
for i in range(4,N+1,2):
    a[i]=1
for i in range(3,N+1,2):
    if a[i]==0:
        for j in range(i*i,N+1,i):
            a[j]=1

for i in range(3,N+1,2): if a[i]==0: prime.append(i) #%% #or the pow(,,) function, already implemented def expo(base,exp,mod): if exp==0: return 1 if exp%2==0: return (expo(base,exp//2,mod)2)%mod else: return (base*expo(base,(exp-1)//2,mod)2)%mod

def P(p): q=p-1 while q%2==0: q=q//2

pow2 = expo(2,q,p)
pow3 = expo(3,q,p)
return (pow2==pow3 and pow2==1)

Nr=0 for p in prime: P_ = P(p) if (p % 24 == 23) != P_: print(p, p % 24) Nr=Nr+1 print("{0} solutions have been generated.".format(Nr))


EDIT $3$: I posted my own answer, to summarize and clarify all of our findings. Indeed, a prime satisfying $(P)$ must be $1$ or $23$ modulo $24$. The ony "mistery" left is to give a complete description of the primes which are $1$ modulo $24$ satisfying $(P)$, but probably this is too difficult.

  • 1
    @nocomment : Those are Legendre/Jacobi/Kronecker symbols. – Eric Towers Aug 02 '24 at 21:49
  • Before posing your question plausibly, it would be necessary to prove that of the infinity of primes congruent to $-1$ modulo $24$ (the first six are $23,47,71,167,191,239$) none divides any integer of the form $2^n+3^m$. That is not evident, unless the equivalence you give proves it, in which case I would appreciate it if you could be a little more explicit on this point. – Ataulfo Aug 02 '24 at 22:40
  • 1
    @Piquito If $2^n+3^m\equiv 0 \pmod p$ then $2^n\equiv -3^m\pmod p$. But the left hand is a quadratic residue and the right hand is not (trusting that the OP has computed the Legendre symbols correctly). – lulu Aug 02 '24 at 23:11
  • Are $n$ and $m$ allowed to be $0$? If not, then the primes $2$ and $3$ obviously satisfy property $(P)$. – Geoffrey Trang Aug 03 '24 at 01:19
  • @GeoffreyTrang : According to ISO 80000-2, the natural numbers include $0$. I understand that not everyone subscribes to international conventions that reduce ambiguity, but here's an opportunity to do so. – Eric Towers Aug 03 '24 at 02:17
  • @GeoffreyTrang Clearly they are allowed here. The OP ist using them in multiple examples for the small primes, including 2 and 3. – no comment Aug 03 '24 at 09:05
  • After the while loop to find q, just do return 1 == pow(2,q,p) == pow(3,q,p). No need to write your own slower expo. – no comment Aug 03 '24 at 14:11
  • Yeah, I forgot there is already implemented the fast modular exponentiation function. – Paul Rebenciuc Aug 03 '24 at 14:14

5 Answers5

5

Question: Must a prime $p$ satisfying $(P)$ have the form $p\equiv 23 (\text{mod}\: 24)$?

No. For example, $p=601$ satisfies $(P)$, and $p\equiv 1 (\text{mod}\: 24)$.

Test script:

def powers_modulo(base, mod):
    powers = set()
    power = 1
    while power not in powers:
        powers.add(power)
        power = power * base % mod
    return powers

def P(p): pow2 = powers_modulo(2, 601) pow3 = powers_modulo(3, 601) return all( (a+b) % p != 0 for a in pow2 for b in pow3 )

p = 601 print(P(p), p % 24)

Output (Attempt This Online!):

True 1

All exceptions up to 50000 (showing $p$, $p$ modulo 24, and the test result):

601 1 True
4297 1 True
6553 1 True
11113 1 True
12073 1 True
12409 1 True
12457 1 True
15241 1 True
16633 1 True
17209 1 True
17881 1 True
20809 1 True
31033 1 True
33721 1 True
36529 1 True
40153 1 True
47017 1 True
47497 1 True
47881 1 True
49369 1 True
49417 1 True

Found with this script in ~44 seconds:

import math

def powers_modulo(base, mod): powers = set() power = 1 while power not in powers: powers.add(power) power = power * base % mod return powers

def P(p): pow2 = powers_modulo(2, p) pow3 = powers_modulo(3, p) for a in pow2: if -a % p in pow3: return False return True

def primes_under(N): for n in range(2, N): for d in range(2, math.isqrt(n)+1): if not n % d: break else: yield n

for p in primes_under(50000): P_ = P(p) if (p % 24 == 23) != P_: print(p, p % 24, P_)

Attempt This Online!

  • 1
    We have only xamples $\equiv1\bmod24$. Where are the other residues prime to $2$ and $3$? – Oscar Lanzi Aug 03 '24 at 00:58
  • 2
    @OscarLanzi I don't know. Maybe there aren't any. – no comment Aug 03 '24 at 01:00
  • @PaulRebenciuc Hmm? What do you mean? What other residues? Are you under the impression that I'm not already checking all? – no comment Aug 03 '24 at 08:56
  • @nocomment No, you did it perfectly. I mean to use the sieve of Eratosthenes, and check for primes of the desired congruence class, even beyond that 50000 margin. I hope I get the code soon. – Paul Rebenciuc Aug 03 '24 at 09:33
  • @PaulRebenciuc Looking forward to your code :-). I don't see how you want to use the sieve of Eratosthenes. Unless you mean just for finding the primes, but that takes my code only about 0.1 seconds of the 44 seconds, so the sieve can't really help with that. – no comment Aug 03 '24 at 13:13
  • @nocomment The sieve is used only to generate all the primes, as fast as possible, there is no other purpose. I agree that it is not much faster than your code, but still it is a good idea to use it. – Paul Rebenciuc Aug 03 '24 at 13:16
  • @PaulRebenciuc Oh, I just realized you already did post the code and more things. Didn't expect it in the question. I think it should be in an answer instead. – no comment Aug 03 '24 at 14:01
4

Let me summarize all the answers received here, and many thanks to @Oscar, @Einar, @nocomment for their contribution. Remember that we want primes $p$ with property $(P)$: $p\nmid 2^n+3^m,\forall n,m\in\mathbb{N}$.

As noted in my post, $p=2$ and $p=3$ must be discarded. Hence, any other prime is of the form: $p\equiv 1,5,7,11,13,17,19,23 (\text{mod} \: 24)$. I proved that any prime with $p\equiv 23 (\text{mod} \: 24)$ has property $(P)$. @Einar Rødland found a nice characterisation, and let me give my own proof (which also shows how to choose $n,m$ if they exist):

Lemma. Let $p\geq 3$ be a prime number. Then $p$ has $(P)$ if and only if $2^q\equiv 3^q\equiv 1 (\text{mod} \: p)$, where $p-1=2^rq,r\in\mathbb{N}^\ast, 2\nmid q$.

Proof: $(\Leftarrow)$ Suppose that there are $n,m\in\mathbb{N}, p|2^n+3^m\Rightarrow 2^n\equiv -3^m (\text{mod} \: p)$. But then: $(2^n)^q\equiv (-3^m)^q\Rightarrow 1\equiv (2^q)^n\equiv -(3^q)^m\equiv -1 (\text{mod} \: p)$, a contradiction.

$(\Rightarrow)$ Suppose that $2^q\not\equiv 1 (\text{mod} \: p)$. If we denote $k:=\gamma_p(2)$ the Gaussian/multiplicative order, then we have: $k\nmid q$. Since $k|p-1=2^rq$, it implies that $k=2^is$ for some $i\in\overline{1,r}$ and $s|q$. But this means: $2^{k/2}\equiv -1\Rightarrow p|2^{k/2}+3^0$, contradicting $(P)$. Similarly, if we assume that $3^q\not\equiv 1 (\text{mod} \: p)$, then for $l:=\gamma_p(3)$ we have: $p|2^0+3^{l/2}$, contradicting $(P)$. $\Box$

As @Oscar noted, we do have a restriction on the possible residues modulo $24$, which is also consistent with our previous computer simulations:

Proposition. Let $p$ be a prime number, satisfying $(P)$. Then $p\equiv 1,23 (\text{mod} \: 24)$.

Proof: Using the notations from the previous Lemma, we have: $2^q\equiv 3^q\equiv 1 (\text{mod} \: p)$. Since $q|(p-1)/2$, this implies: $2^{(p-1)/2}\equiv 3^{(p-1)/2}\equiv 1 (\text{mod} \: p)$. Using Euler's criterion, this is equivalent to: $$\left(\frac{2}{p}\right)=\left(\frac{3}{p}\right)=1.$$ The first Legendre symbol is translated as: $p\equiv 1,7 (\text{mod} \: 8)$, and the other symbol as: $p\equiv 1,11 (\text{mod} \: 12)$. Out of the four total combinations of congruences, only two are possible:
$(i)$ $p\equiv 1 (\text{mod} \: 8)$ and $p\equiv 1 (\text{mod} \: 12)$, this leads to $p\equiv 1 (\text{mod} \: 24)$;

$(ii)$ $p\equiv 7 (\text{mod} \: 8)$ and $p\equiv 11 (\text{mod} \: 12)$, this leads to $p\equiv 23 (\text{mod} \: 24)$. $\Box$

2

We prove nondivisibility when $p=601$.

The proof is similar to that given here for $p=23$, except it involves higher power residues.

Modulo $601$, which is understood in the equivalences that follow, we have $729\equiv128\implies 3^6\equiv2^7$. Now suppose that $2^n+3^m\equiv0$. Since $(a+b)|(a^7+b^7)$, we have $2^{7n}+3^{7m}\equiv3^{6n}+3^{7m}\equiv0$. Then $3^k\equiv-1$ where $k=|6n-7m|$ is a whole number, but no such $k$ actually exists because $3$ turns out to have odd (multiplicative) order (order = $75$).


The above method of proof works in two situations:

  • An odd power of $3$ is equivalent to some power of $2\bmod p$ and $2$ is then found to have odd order, or

  • An odd power of $2$ is equivalent to some power of $3\bmod p$ and $3$ is then found to have odd order.

These options actually imply that both $2$ and $3$ have odd multiplicative order $\bmod p$, which (for $p>3$) requires both $2$ and $3$ to be quadratic residues $\bmod p$. This implies that nondivisibility can he proved by this method only if $p\equiv\pm1\bmod24$.

For $p\equiv-1\bmod24$ a quadratic residue will always have odd order, as the Euler totient of $p$ is twice an odd number, so nondivisibility of $2^n+3^m$ always holds. For $p\equiv+1\bmod24$ we need a higher power residue to guarantee odd order, so only some of these primes will give this nondivisibility.

Oscar Lanzi
  • 48,208
2

Adding some more info about the solutions $\equiv 1 \pmod {24}$: Because $2$ and $3$ both have odd order, they are 8th power residues modulo $p$. In particular, $4$th (biquadratic) and theorems of Gauss give that $p$ is of the form $a^2 + (24 b)^2$. https://en.wikipedia.org/wiki/Quartic_reciprocity.

In the case of $601$: $5^2 + 24^2$, showing that you cannot get more factors beyond $24$.

You can also give a characterization in terms of splitting properties in a certain field extension, as in this question: About the parity of $ord_p(7)$ or this MO question: https://mathoverflow.net/questions/372450/parity-of-the-multiplicative-order-of-2-modulo-p and this allows you to compute the density of such primes.

Let $j\geq 3$, then the following are equivalent with at most finitely many exceptions:

  • $p\equiv 1 \pmod {24}$ and $2^j\Vert p-1$ and $2$ and $3$ are $2^j$th powers modulo $p$.
  • $p$ is split in the field $K_j = \mathbb Q(1^{1/2^j},2^{1/2^j},3^{1/2^j})$ but not in $L_j=K_j(1^{1/2^{j+1}})$.

(The finitely many exceptions come from my inability to write down an integral basis or to prove that the elements I wrote down generate the ring of integers.)

The density of the primes $\equiv 1 \pmod {24}$ that we are looking for is then $$\sum_{j\geq 3} \left(\frac1{[K_j:\mathbb Q]}-\frac1{[L_j:\mathbb Q]}\right) \,.$$

For $j\geq 3$ the following should be true:

  • $[L_j:K_j]=2$
  • $[K_j:\mathbb Q]= 2^{3j-2}$

Assuming this, the density is $$\sum_{j\geq3} \frac1{2^{3j-1} } = \frac1{2^{5}\cdot7}=\frac1{224} \,.$$

This predicts about $$\frac{50000}{224\log(50000)}\approx 20.63$$ such primes below 50000, compared to the actual 21 found in another answer here.

In other words, among all the primes that are $\equiv 1 \pmod {24}$, of them $\frac1{28}$ are solutions to the problem.

Bart Michels
  • 26,985
  • 6
  • 59
  • 123
1

Just to add some comments to the existing solution.

For a given prime $p$, there are $n,m$ so that $p\,|\,2^n+3^m$ if and only if there is either an $n$ for which $2^n\equiv-1\pmod{p}$ or $3^m\equiv-1\pmod{p}$.

Let $p-1=2^rq$ with $q$ odd. If $2^q\equiv1\pmod{p}$, no such $n$ exists; similarly, if $3^q\equiv1\pmod{p}$, no such $m$ exists. In fact, for any $x$ not divisible by $p$, the powers $x^{(p-1)/2^k}$ will either all be 1 modulo $p$, or the smallest $k$ for which it is not 1 it will be $-1$ modulo $p$.

This gives us a faster test: just compute $2^q$ and $3^q\pmod{p}$, and if they are both equal to $1$ modulo $p$, there are no $n,m$ for which $p\,|\,2^n+3^m$. Otherwise, such $n,m$ exist.

Using SAGE, this method used 58 seconds to find 2946 primes below 10,000,000 and not equal to $23\pmod{24}$ with this property; up to 100,000,000 took 8 min 34 sec and found 25707 such primes. These primes are all equal to $1\pmod{24}$, and the majority (appr 7/8) are $25\pmod{48}$.

As for predicting such primes without having to test them one by one, my best idea would be to do something similar to Legendre symbols, but with $x^q\pmod{p}$ for $x=2,3$ instead of $x^{p-1}\equiv\left(\frac{x}{p}\right)\pmod{p}$.


Here is my SAGE code:

def Ptest(p, S=[2,3], log=True):
    R = Zmod(p)
    Sol = []
    q = p-1
    while q%2==0:
        q /= 2
    Sol = [s for s in S if R(s)^q!=1]
    if log: print('%s: q=%s, Sol=%s'%(p,q,Sol))
    return Sol

SOL = [] for p in prime_range(5,10000000): sol = Ptest(p, log=False) if not sol and p%24!=23: SOL.append(p)

print('Primes found: %s'%len(SOL)) ```

Einar Rødland
  • 11,378
  • 23
  • 39
  • 1
    Can you check the residues of those generated primes? Is there anyone not 1 mod 24? – Paul Rebenciuc Aug 03 '24 at 11:24
  • 1
    @PaulRebenciuc They are all 1 mod 24. I'll add a comment on that in my answer. – Einar Rødland Aug 03 '24 at 11:34
  • I checked your answer and I wrote an adapted Python code, you are absolutely correct! Indeed, a prime $p$ has property $(P)$ iff $2^q\equiv3^q\equiv 1 (\text{mod} : p)$, where $p-1=2^rq, 2\nmid q$. – Paul Rebenciuc Aug 03 '24 at 11:58
  • 1
    @PaulRebenciuc this would imply that divisibility occurs for some $(m, n)$ except if the prime has residue $\pm1\bmod 24$ (and the obvious cases $2$ and $3$). See the generalization I added to my answer. – Oscar Lanzi Aug 03 '24 at 13:25
  • 1
    I saw the edit, well done! I also wrote my own answer at the same time, I realized the same thing. – Paul Rebenciuc Aug 03 '24 at 13:50
  • 1
    "the majority (appr 7/8) are $25\bmod48$". Because then we need $2$ or $3$ to be only an eighth-power residue for nondivisibility to work. Having $1\bmod48$ would require $2$ or $3$ to be at least a $16$th-power residue. – Oscar Lanzi Aug 03 '24 at 16:22