题解 | #与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")
逐个搜索即可
查看11道真题和解析

