题解 | #与7无关的数#

与7无关的数

https://www.nowcoder.com/practice/776d401bf86d446fa783f0bef7d3c096

//挺常规的一道题
#include "stdio.h"
#include "math.h"
using namespace std;
bool sevenRelated(int x){
    if(x%7 == 0)
        return true;//true为与7相关的数
    while (x > 0){
        if(x%10 == 7)
            return true;
        x = x/10;
    }
    return false;
}

int main(){
    int n;
    while (scanf("%d",&n)!=EOF){
        int sum = 0;
        for (int i = 1; i <= n; ++i) {
            if(!sevenRelated(i))
                sum += pow(i,2);
        }
        printf("%d\n",sum);
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务