https://ac.nowcoder.com/acm/contest/318/L

题解:预处理一下
由于T很小,所以我们只需要从1~n for一遍就可以了,对每个数判断一下这个数是否为与6相关的数,然后在将那些与6无关的数的平方加起来就可以了。由于数据范围较大,记得开long long来存储答案。

C++版本一

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=1000000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
ll a[N];
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    ll sum=0;
    for(ll i=1;i<N;i++){
        int flag=1;
        if(i%6==0){
            flag=0;
        }
        t=i;
        while(t){
            if(t%10==6){
                flag=0;
                break;
            }
            t/=10;
        }
        if(flag){
            sum+=i*i;
        }
        a[i]=sum;
    }
    while(~scanf("%d",&t)){
        while(t--){
            scanf("%d",&n);
            printf("%lld\n",a[n]);

        }
    }


    //cout << "Hello world!" << endl;
    return 0;
}

C++版本二

#include <cstdio>
typedef long long ll;

int n,_;
bool check(int x){
    if(x%6 == 0) return 1;
    while(x){
        if(x%10 == 6) return 1;
        x /= 10;
    }
    return 0;
}
ll sqr(ll x){return x * x;}

int main(){
    for(scanf("%d",&_);_;_--){
        scanf("%d",&n);
        ll ans = 0;
        for(int i = 1;i <= n;i++){
            if(check(i)) continue;
            ans += sqr(i);
        }
        printf("%lld\n",ans);
    }
    return 0;
}