题解 | #与7无关的数#
与7无关的数
http://www.nowcoder.com/practice/776d401bf86d446fa783f0bef7d3c096
注意判断:
- 7的倍数:i%7==0
- 十位上7: i/10==7
- 个位上7: i%10==7
#include <iostream>
#include <cstdio>
using namespace std;
int sumUnder7(int n){
int sum = 0;
for(int i = 1 ; i <= n ; i++){
if(i>=7){
if(i%7==0 || i%10 == 7 || i/10 == 7)
continue;
sum += i*i;
}else{
sum += i*i;
}
}
return sum;
}
int main(){
int n = 0;
// while(1){
// cout << "请输入一个小于100的正整数: " << endl;
// cin >> n;
// if(n<=0 | n >100)
// continue;
// printf("%d\n",sumUnder7(n));
// }
//cout << "请输入一个小于100的正整数: " << endl;
cin >> n;
if(!(n<=0 | n >100))
printf("%d\n",sumUnder7(n));
return 0;
}