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.
p=1000000; found=false;
while ~found
p=prevprime(p-1);
ps=num2str(p);
found=true;
pset=p;
for i=1:5
ps=[ps(2:end),ps(1)];
if ~isprime(str2double(ps))
found=false;
break
else
pset(end+1)=str2double(ps);
end
end
end
pset
finds the largest such is the first number listed below in the cycle:
999331 993319 933199 331999 319993 199933
|
Posted by Charlie
on 2024-11-05 11:51:45 |