topic description
problem solving ideas
Traverse each number in 1 - n, judge whether each digit meets the condition, add the number if it is satisfied, and continue the loop if it is not satisfied.
Implementation code
#include <iostream>
using namespace std;
const int N = 10010;
int res;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i ++)
{
int x = i;
while (x)
{
int t = x % 10;
x /= 10;
if (t == 2 || t == 0 || t == 9 || t == 1)
{
res += i;
break;
}
}
}
cout << res << endl;
return 0;
}