标签:ble lld png for under input using html ems
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000) 第2 - T + 1行:每行1个数N。(1 <= N <= 10^6)
共T行,每行一个数,对应T个测试的计算结果。
5 4 5 6 7 8
30 55 91 91 155
因为范围有点大,所以暴力估计会T,所以预处理一下,把与7有关的数存起来,然后计算和减去与7有关的数
/* data:2018.7.14 author:authorgsw link:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1082 */ #define ll long long #define IO ios::sync_with_stdio(false); #include<math.h> #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; ll vis[1000005];int len=0; bool judge(ll n) { if(n%7==0)return true; while(n!=0) { if(n%10==7)return true; n=n/10; } return false; } void init() { memset(vis,0,sizeof(vis)); for(int i=1;i<1000005;i++) if(judge(i))vis[len++]=i; } int main() { int t;ll n; init(); scanf("%d",&t); while(t--) { ll ans=0; scanf("%lld",&n); ans=n*(n+1)*(2*n+1)/6; for(int i=0;i<len;i++) { if(vis[i]>n)break; ans=ans-vis[i]*vis[i]; } printf("%lld\n",ans); } }
标签:ble lld png for under input using html ems
原文地址:https://www.cnblogs.com/fantastic123/p/9311194.html