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?

Performance improvements:
1) Remove all primes with digit 0,2,4,5,6,8 because they will not lead to a prime during permutation. //42243 -> 11 ms.
2) Don't use ToString() to rotate digits. Use n%10 instead.

Problem35 = 55 elapsed time: 11 ms. Test Passed.
Geen opmerkingen:
Een reactie posten