题解 | 与7无关的数
#include <bits/stdc++.h>
using namespace std;
bool ob7(int x){
while(x!=0){
if(x%10==7)return true;
x/=10;
}
return false;
}
bool is7(int x){
if(x%7==0)return true;
else if(ob7(x))return true;
else return false;
}
int main(){
int n;
while(cin>>n){
int ans=0;
for(int i=1;i<=n;i++){
if(!is7(i))ans+=i*i;
}
cout<<ans<<endl;
}
}
数据量极小,直接枚举
文远知行公司福利 521人发布