思路
题目描述很简单,只要数字能整除 或数字中含有 ,即可挑 。
那么枚举 的每一个数,然后把符合要求的数的个数 cnt 求一下即可。
代码
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int cnt = 0;
for (int i = 1; i <= n; i++) {
// 能把7整除
if (i % 7 == 0) {
cnt++;
} else { // 含 7
int tmp = i;
while (tmp) {
if (tmp % 10 == 7) {
cnt++;
break;
}
tmp /= 10;
}
}
}
cout << cnt << endl;
return 0;
}

京公网安备 11010502036488号