1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream> bool check(int n) { while (n != 0) { int k = n % 10; if (k == 2 || k == 0 || k == 1 || k == 9) { return true; } n /= 10; } return false; } int main() { int n; std::cin >> n; long long sum; for (int i = 1; i <= n; i++) { if (check(i)) { sum += i; } } std::cout << sum; return 0; }