51Nod——N1082 与7无关的数

https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1082

题目来源: 有道难题
基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题
 收藏
 关注
一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7,则称其为与7相关的数。求所有小于等于N的与7无关的正整数的平方和。
 
例如:N = 8,<= 8与7无关的数包括:1 2 3 4 5 6 8,平方和为:155。
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000)
第2 - T + 1行:每行1个数N。(1 <= N <= 10^6)
Output
共T行,每行一个数,对应T个测试的计算结果。
Input示例
5
4
5
6
7
8
Output示例
30
55
91
91
155

 1 #include <algorithm>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 long long tot,n,t,sum[1000005];
 7 
 8 int main()
 9 {
10     for(long long i=1,ok;i<=1000005;i++)
11     {
12         ok=1;
13         if(i%7!=0)
14         {
15             for(long long j=i;j;j/=10)
16                 if(j%10==7)
17                 {
18                     ok=0;
19                     break;
20                 }
21             if(ok) tot+=i*i;
22         }
23             
24         sum[i]=tot;
25     }
26     scanf("%lld",&t);
27     for(;t--;)
28     {
29         scanf("%lld",&n);
30         printf("%lld
",sum[n]);
31     }
32     return 0;
33 }
——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
原文地址:https://www.cnblogs.com/Shy-key/p/7142165.html