一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7,则称其为与7相关的数。求所有小于等于N的与7无关的正整数的平方和。
第2 - T + 1行:每行1个数N。(1 <= N <= 10^6)Output共T行,每行一个数,对应T个测试的计算结果。Sample Input
5 4 5 6 7 8Sample Output
30 55 91 91 155
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll; //定义了一个longlong型的ll,详细typedef的用法
//https://blog.csdn.net/lioncatch/article/details/80621248
ll a[1000005]; //创造了一个longlong数组
ll solve(ll x) //函数功能为 判断是否符合题意的数
{
if(x%7==0) return 1;
int ans=0;
while(x>1)
{
int t=x%10;
if(t==7)
{
ans=1;
break;
}
x/=10;
}
if(ans) return 1;
return 0;
}
int main()
{
ll T,n;
memset(a,0,sizeof(a));
scanf("%lld",&T);
for(ll i=1;i<=1000000;i++)//a数组里面存了从1到100000的每一个答案,需要 //时直接a[i]调用
{
if(!solve(i))
a[i]=a[i-1]+i*i;
else a[i]=a[i-1];
}
while(T--)
{
scanf("%lld",&n);
printf("%lld\n",a[n]);
}
return 0;
}