题目如下:
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
How many circular primes are there below one million?
代码如下:
clear;clc;close all
t0 = 0;
for p = primes(1e6)
n = ceil(log10(p+1));
m = mod(floor(p./10.^(n-1:-1:0)),10);
if all(isprime(10.^(n-1:-1:0)*hankel(m,circshift(m,1))))
t0 = t0 + 1;
end
end