题解 | 挑7
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
int counter = 0;
for (int i = 1; i <= n; i ++) {
if (i % 7 == 0) {
counter ++;
} else {
string num = to_string(i);
if (num.find('7') != num.npos) {
counter ++;
}
}
}
cout << counter << endl;
return 0;
}
// 64 位输出请用 printf("%lld")
查看1道真题和解析