首页 > 其他 > 详细

51Nod 1082 与7无关的数

时间:2021-04-05 21:21:04      阅读:16      评论:0      收藏:0      [点我收藏+]

打表,先把小于等于 N 的且与 7 无关的正整数找出来,然后再预处理出小于等于N的这些正整数平方和。

const int N=1e6+10;
bool vis[N];
LL sum[N];

bool check(int x)
{
    if(x % 7 == 0) return true;

    while(x)
    {
        int t=x%10;
        if(t == 7) return true;
        x/=10;
    }
    return false;
}

void init()
{
    for(int i=1;i<N;i++)
        if(check(i))
            vis[i]=true;

    LL res=0;
    for(int i=1;i<N;i++)
    {
        if(!vis[i]) res+=(LL)i*i;
        sum[i]=res;
    }
}

int main()
{
    init();

    int T;
    cin>>T;
    while(T--)
    {
        int x;
        cin>>x;
        cout<<sum[x]<<endl;
    }
    //system("pause");
    return 0;
}

51Nod 1082 与7无关的数

原文:https://www.cnblogs.com/fxh0707/p/14618830.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!