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.
whileloop to find q, just doreturn 1 == pow(2,q,p) == pow(3,q,p). No need to write your own slowerexpo. – no comment Aug 03 '24 at 14:11