一个正整数,如果它能被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个测试的计算结果。
Sample Input
5
4
5
6
7
8
Sample Output
30
55
91
91
155
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
long long sum[1000010];
long long yang(long long a)
{
long long ans=0,ans1=0;
long long t=a,n=a;
while(t)
{
t/=10;
ans1++;
}
while(a)
{
if(a%10==7)
break;
a/=10;
ans++;
}
if(ans>=ans1&&n%7!=0)
return n*n;
else
return 0;
}
int main()
{
long long i,n,t;
scanf("%lld",&t);
for(i=0;i<1000000;i++)
{
sum[i]=sum[i-1]+yang(i);
}
while(t--)
{
scanf("%lld",&n);
printf("%lld\n",sum[n]);
}
return 0;
}