小明对数位中含有 2、0、1、92、0、1、9 的数字很感兴趣(不包括前导 00),在 11 到 4040 中这样的数包括 1、2、9、101、2、9、10 至 32、3932、39 和 4040,共 2828 个,他们的和是 574574。
请问,在 11 到 nn 中,所有这样的数的和是多少?
输入格式
共一行,包含一个整数 nn。
输出格式
共一行,包含一个整数,表示满足条件的数的和。
数据范围
1≤n≤100001≤n≤10000
输入样例:
40
输出样例:
574
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
bool check(int x){
while(x){
int t = x % 10;
if (t == 0 || t == 2 || t == 1 || t == 9) return true;
x /= 10;
}
return false;
}
int main(){
scanf("%d", &n);
int res = 0;
for (int i = 1; i <= n; i ++){
if (check(i))
res += i;
}
cout << res << endl;
return 0;
}