题解 | #与7无关的数#

与7无关的数

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

#include <iostream>
using namespace std;

bool detect(int a)
{
    int s;
    while(a!=0)
    {
        s=a%10;
        if(s==7)
        {
            return true;
        }
        a/=10;
    }
    return false;
}

int main() {
    int a, b;
    int n;
    cin>>n;
    int sum=0;
    for(a=1;a<=n;a++)
    {
        if((a%7!=0)&&(!detect(a)))
        {
            sum+=a*a;
        }
    }
    // while (cin >> a >> b) { // 注意 while 处理多个 case
    //     cout << a + b << endl;
    // }
    cout<<sum<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

逐个搜索即可

全部评论

相关推荐

积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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