A circular prime is one in which
all cyclic permutations of its digits
are prime. For example, 1193 is
a circular prime because 1931,
9311, and 3119 are prime.
Find the
largest circular prime less than
1,000,000.
The answer is 999331 which is, in fact, the largest known circular prime which is not a repunit.
(1111111111111111111 for example is a circular prime)
999331
993319
939391
939193
933199
919393
393919
391939
331999
319993
199933
193939
99371
93911
93719
91193
71993
39119
37199
19937
19391
11939
9377
9311
7937
7793
3779
3119
1931
1193
991
971
919
733
719
373
337
311
199
197
131
113
97
79
73
71
37
31
17
13
11
7
5
3
2
(my algorithm skipped any number with an even digit so I manually added the final entry: 2)
-----------------
for n in range(999999,1,-2):
strn = str(n)
fail = False
for digit in '02468':
if digit in strn:
fail = True
if fail:
continue
number_digits = len(strn)
eabcd = strn
for ind in range(number_digits):
if not isprime(int(eabcd)):
fail = True
break
eabcd = eabcd[-1] + eabcd[:-1]
if fail:
continue
print(n)
|
Posted by Larry
on 2024-11-05 11:23:12 |