问题 L: 与7无关的数

题目链接http://codeup.cn/problem.php?cid=100000588&pid=11

题目描述
一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7,
则称其为与7相关的数.现求所有小于等于n(n<100)的与7无关的正整数的平方和。

输入
案例可能有多组。对于每个测试案例输入为一行,正整数n,(n<100)

输出
对于每个测试案例输出一行,输出小于等于n的与7无关的正整数的平方和。

样例输入
6
12
18

样例输出
91
601
1575

代码

#include<stdio.h>

int main() {
	int n;
	while(scanf("%d", &n) != EOF) {
		int sum = 0;
		for(int i = 0; i <= n; i++)
			if((i / 10 != 7) && (i % 10 != 7) && (i % 7 != 0))
				sum += i * i;
		printf("%d\n", sum);
	}
	return 0;
}
发布了148 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Rhao999/article/details/104172978
今日推荐