问题 L: 与7无关的数
时间限制: 1 Sec 内存限制: 32 MB
献花: 30 解决: 27
[献花][花圈][TK题库]
题目描述
一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7,
则称其为与7相关的数.现求所有小于等于n(n<100)的与7无关的正整数的平方和。
输入
案例可能有多组。对于每个测试案例输入为一行,正整数n,(n<100)
输出
对于每个测试案例输出一行,输出小于等于n的与7无关的正整数的平方和。
样例输入
6
12
18
样例输出
91
601
1575
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <ctime>
using namespace std;
bool ReW7(int a)
{
if (a % 7 == 0)return false;
while (a && a % 10 != 7)
a /= 10;
if (a)return false;
return true;
}
int main()
{
#ifdef _DEBUG
//freopen("data.txt", "r+", stdin);
fstream cin("data.txt");
#endif // _DEBUG
const int MaxN = 110;
int n, curMax = 0, Pow[MaxN] = {0};
while (cin >> n)
{
if (curMax < n)
{
for (int i = max(1, curMax); i <= n; ++i)
ReW7(i)?Pow[i] = Pow[i - 1] + i * i:Pow[i] = Pow[i - 1];
curMax = n;
}
cout << Pow[n] << endl;
}
#ifdef _DEBUG
cin.close();
#ifndef _CODEBLOCKS
system("pause");
#endif // !_CODEBLOCKS
#endif // _DEBUG
return 0;
}
/**************************************************************
Problem: 2048
User: Sharwen
Language: C++
Result: 升仙
Time:0 ms
Memory:1704 kb
****************************************************************/