A circular prime is a prime number that remains prime as each leftmost digit (most significant digit), in turn, is moved to the right hand side. For instance, the number 19937 is a circular prime, since all numbers in the sequence 19937, 99371, 93719, 37199 and 71993 are prime numbers. Your objective is to write a program that, given a range, computes the number of circular primes in that range.
The input consists of a sequence of pairs of integers i and j, with one pair of integers per input line. All integers will be less than 1,000,000 and greater or equal to 100. You can assume that in any pair i is lesser or equal than j. You should process all pairs of integers, and for each such pair, count the number of circular primes between i and j, including i and j. Input is terminated by a line just with the number ‘-1’.
For each pair of input integers, defining a range, the output should be: ‘No Circular Primes.’ (if there are no circular primes in the range), ‘1 Circular Prime.’ (if only one circular prime exists in the range), or ‘n Circular Primes.’ (if there are n circular primes in the range, and n is greater than one).
範例輸入 1
1000 1100 100 120 100 1000 -1
範例輸出 1
No Circular Primes. 1 Circular Prime. 12 Circular Primes.
Pro 專屬功能: 查看這題在歷屆 CPE 出現過幾次 — 升級以解鎖.