Primes whose sum of digits is 25: Difference between revisions

Content added Content deleted
(Added C++ solution)
m (Minor edit to C++ code)
Line 98: Line 98:
}
}


void countAll(const std::string& str, int rem, int& count) {
void count_all(const std::string& str, int rem, int& count) {
if (rem == 0) {
if (rem == 0) {
switch (str.back()) {
switch (str.back()) {
Line 113: Line 113:
} else {
} else {
for (int i = 1; i <= std::min(9, rem); ++i)
for (int i = 1; i <= std::min(9, rem); ++i)
countAll(str + std::to_string(i), rem - i, count);
count_all(str + std::to_string(i), rem - i, count);
}
}
}
}
Line 132: Line 132:
count = 0;
count = 0;
auto start = std::chrono::steady_clock::now();
auto start = std::chrono::steady_clock::now();
countAll("", 25, count);
count_all("", 25, count);
auto end = std::chrono::steady_clock::now();
auto end = std::chrono::steady_clock::now();
std::cout << "\nThere are " << count
std::cout << "\nThere are " << count