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 10000?write in c++
What is giving you problems?
rotation of numbers after getting prime numbers
int mod = prime % 10; int divisor = prime / 10; // could be replaced with a recursive function to find the power of ten to // multiply mod by, but with only four possibilites...... if( divisor < 10 ) mod *= 10; else if( divisor < 100 ) mod *= 100; else if( divisor < 1000 ) mod *= 1000; else mod *= 10000; divisor += mod; // divisor is prime shifted right one digit // not tested, try with a few and cout results
Join our real-time social learning platform and learn together with your friends!