题解 | #与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);
}
}