Jump to content

Primes whose sum of digits is 25: Difference between revisions

m
C++ - minor performance improvement
m (C++ - minor performance improvement)
Line 204:
}
 
voidint count_all(const std::string& str, int rem, int& count) {
int count = 0;
if (rem == 0) {
switch (str.back()) {
Line 219 ⟶ 220:
} else {
for (int i = 1; i <= std::min(9, rem); ++i)
count += count_all(str + std::to_stringchar('0' + i), rem - i, count);
}
return count;
}
 
Line 236 ⟶ 238:
std::cout << '\n';
 
count = 0;
auto start = std::chrono::steady_clock::now();
count = count_all("", 25, count);
auto end = std::chrono::steady_clock::now();
std::cout << "\nThere are " << count
1,777

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.