描述
一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7, 则称其为与7相关的数.现求所有小于等于n(n<100)的与7无关的正整数的平方和。
输入描述:
案例可能有多组。对于每个测试案例输入为一行,正整数n,(n<100)
输出描述:
对于每个测试案例输出一行,输出小于等于n的与7无关的正整数的平方和。
示例1
输入:
21
输出:
2336
#include <iostream>
using namespace std;
bool isRelative(int n);
int main() {
int n, sum = 0;
while (cin >> n) { // 注意 while 处理多个 case
for(int i = 0; i <= n ; i++){
if(!isRelative(i)) sum += i*i;
}
}
cout << sum << endl;
}
bool isRelative(int n){
if(n % 7 == 0) return true;
while(n != 0){
if(n % 10 == 7) return true;
n = n/10;
}
return false;
}