题解:
#include <bits/stdc++.h>
using namespace std;
bool f(int x)
{
while(x)//当x为0时停止
{
int y = x %10;//最后一位
if(y == 2 || y == 0 || y == 1 || y == 9)return true;
x /= 10;//最低位删除,从而使其可以遍历到每一位
}
return false;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;cin >> n;//数据的规模并不会超过int
int ans = 0;//赋初值
for(int i = 1; i <= n; i++)//题目要求为1开始,所以i = 1
{
if(f(i))ans += i;//f()判断是否为特别数
}
cout << ans;
return 0;
}