int main() { // The leftmost digit has to be 2, 3, 5, or 7 // The rightmost digit has to be 3 or 7 // Sieve of Erathosthenes to find primes below 1000000 int p = 2, multiple, len, sum = 0, count = 0; while (count != NUM_PRIMES) { if (number[p] == 0) { number[p] = 2; len = numLength(p); if ((len > 1) && (truncLtoR(p,len) > 0) && (truncRtoL(p,len) > 0)) { sum += p; count++; } multiple = p * 2; while (multiple < MAX) { number[multiple] = 1; multiple += p; } } p++; } printf("%d\n", sum); }
std::vector<int> intToVec(int n) { std::vector<int> retVec; auto lenN = numLength(n); retVec.reserve(lenN); for (int i = 0; i < lenN; ++i) { retVec.push_back(n % 10); n /= 10; } return retVec; }
/* Converts num into a '\0' ended string in str parameter*/ void intToString(char* str, int num) { int length = numLength(num); int numLength = length; int i; if (num < 0) { str[length - 1] = '-'; num *= -1; numLength--; } for (i = 0; i < numLength; i++) { str[i] = (char)(num % 10 + '0'); num /= 10; } reverseCharArray(str, length); str[length] = '\0'; }