北京大学机试 与7无关数 Easy

基本思想:

无;

关键点:

无;

#include<iostream>
#include<string>
#include<vector>
using namespace std;

bool charge(int n) {
    if (n % 7 == 0)
        return true;
    while (n != 0) {
        if (n % 10 == 7)
            return true;
        n /= 10;
    }
    return false;
}

int main() {
    int n;
    while (cin >> n) {
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            if (!charge(i))
                cnt += i * i;
        }
        cout << cnt << endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/songlinxuan/p/12454219.html