Here are few steps which made sense when analysing the prime numbers
Step 1: For any odd number "$a \in Z^+ $" e.g. 17
Step 2 : $a$ is $2^{n} < a < 2^{n+1}$
Step 3: now get the list starting $ b_i $ where $b_i \equiv 2^{n+1} \pmod a $ as follows
Step 4: $b_1 = 15 $ here, $(32\equiv15 \pmod {17 }$)
Step 5: Then for each step double the result till we again reach the $2^{n}$ as follows
$ b_{i +1}= 2\times b_i(30\equiv13 \pmod {17 }$), in this case
$ 26\equiv9 \pmod {17 }$
$ 18\equiv1 \pmod {17} $
and so on till $b_i = 2^n$
When we make a list it will be $[15, 13, 9, 1,2,4,8,16]$ and the list count $l$ is $8$
$$m = \frac{a-1}{mod\_list\_length} $$
Now $m = \frac{(a-1)}{l}= 2 $
When we run a program in python obviously we get $m = \frac{(a-1)}{l} $.
$a$ is almost always a prime number for any odd when $m \in Z^+$. Python program below to check primality of odd +ve integer. Perhaps we get exceptions!
import math
import time
def find_power_of_two(a):
if a <= 0 or a % 2 == 0:
raise ValueError("Input must be a positive odd integer.")
return int(math.log2(a))
begin = time.time()
Example usage:
a = int(input("Enter a positive odd integer: "))
n = find_power_of_two(a)
print(f"The value of n such that 2^n < {a} < 2^(n+1) is: {n}")
M = 1 << (n + 1)
b = M % a
l = []
sum = 0
while b != (1 << n):
while b < (1 << (n - 1)):
l.append(b)
sum += b
b = b << 1
l.append(b)
sum += b
b = (b << 1) % a
l.append(1 << n)
print(l)
sum += 1 << n
m = (a - 1) / len(l)
print('The ratio to odd integer less 1 by number of moduli is ', m)
print('sum of all moduli are ', sum)
print('The ratio between sum of moduli and a is', sum / a)
if (a - 1) % len(l) == 0:
print(f'{a} is a Prime number')
else:
print(f'{a} is not a prime number')
end = time.time()
print('Time taken to test is', end - begin)
Following python code gives the results by method below and exceptions also displayed. For example, for odd numbers upto 10000, the exceptions (that are not divisible by 3 or 5) are [341, 1387, 1729, 2047, 2701, 2821, 3277, 4033, 4369, 4681, 5461, 6601, 7957, 8321, 8911] These exceptions are falsely detected as Prime numbers by mod function.
from decimal import*
from fractions import Fraction
import time
getcontext().prec = 1000
n = int(input("Enter a number till which you need Prime numbers by moduli method \n:"))
i = 1
l = []
for i in range(9,n):#(2 is only even Prime number, 3 leads to infinite loop. Therefore I have not started from 3)#
if i%2 !=0 and i % 5 != 0 and i % 3 != 0:
l = l + [i]
#print(l)# List of Odd numbers out of divisibility by other than 2, 3, 5
begin = time.time()
nl = []
for j in l:
i = 0
for i in range(j):
if 2 ** i < j < 2 ** (i + 1):
break
m = 2 ** (i - 1)
#print("The numerator for n is = ",m)
M = 2 ** (i + 1)
Max = 2 ** (i + 2)
lst = []
#print(j)
while M != m:
M = M % j
lst = lst + [M]
M = M * 2
lst = lst + [m]
lst = lst + [m * 2]
#print('List of remainders in the list for given odd number is', lst)
rl = lst
#print('Total number of moduli are', len(rl))
ratio = (j - 1) / len(lst)
#print("The ratio between (n-1) and Nom is ", Fraction((j - 1), len(lst)))
# returns Fraction
# print((n-1)//len(lst),",", Fraction((n-1)%len(lst)),"/",len(lst))
if (j - 1) % len(lst) == 0:
nl = nl + [j]
print("list of Prime numbers out of Odd numbers is\n",nl)
print(len(nl))
end = time.time()
print("Time taken to calculate list of Prime numbers is", end - begin)
ls = []
a = 0
for num in range(9, n):
if num > 2:
for i in range(2, num):
if num % i == 0:
break
else:
a += 1
ls = ls + [num]
# print(a, '|',num )
print(ls)
print(len(ls))
using sieve method
Uncommon elements in List
res_list = []
for i in nl:
if i not in ls:
res_list.append(i)
for i in ls:
if i not in nl:
res_list.append(i)
# printing the uncommon
print("The uncommon of two lists is : " + str(res_list))
print(len(res_list))
Even though I thought of relationship with Fermat's little theorem, the nonprime numbers are not exactly the Carmichael numbers.)
One of the important observation I made is due to its association with mod function with $2^n$, any prime of $2^n -1$ will have high $m $ which turns out very fast in running to give the output as prime number or not. Next will be prime numbers of $2^n +1$ forms.
My question is "Is there any way to identify the $m$ as predictable integers?
512→463→365→169→338→115→230→460→359→157→314→67→134→268→536→511→461→361→161→322→83→166→332→103→206→412→263→526→491→421→281→1→2→4→8→16→32→64→128→256→512
. That is $40$ arrows, or period length $40$. And $(561-1)$ is divisible by $40$ (quotient is $14$). So am I doing it right? – Jeppe Stig Nielsen May 21 '23 at 09:04getm(a)=(a-1)/znorder(Mod(2,a))
, then you can calculate what you call herem
for any odd input numbera
(the function will fail for evena
). It will in general return a fraction, for examplegetm(559)
gives93/14
. But for all primes it will give an integer, for examplegetm(563)
gives1
. And for the "exceptional" odd integersa
that we are talking about, it will give an integer as well, even thougha
is composite, like in the example of my first comment,getm(561)
gives14
. – Jeppe Stig Nielsen May 21 '23 at 12:26a
and print those for whichm
is7
:forstep(a=3,+oo,2,getm(a)==7&&print1(a,", "))
Then search OEIS with that: A152307 – Jeppe Stig Nielsen May 23 '23 at 23:10