C++解法,通过取余判断是否是7的倍数,通过字符串查找判断是否含有7.

#include <bits/stdc++.h>>
using namespace std;

int main() {
    int N;
    while (cin >> N) {
        int count = 0;
        string tmp;
        if(N >= 7)
        {
            for(int digit = 7; digit <= N; digit ++)
            {
                tmp = to_string(digit);
                if( (0 == digit%7) || (tmp.npos != tmp.find('7')) )
                {
                    count ++;
                }
            }
        }
        // else N is smaller than 7 so count is still 0
        cout << count << endl;
    }
    return 0;
}