51nod 1082 与7无关的数【打表】

来源:互联网 发布:舒畅 天山童姥 知乎 编辑:程序博客网 时间:2024/06/05 11:29
1082 与7无关的数
题目来源: 有道难题
基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题
 收藏
 关注
一个正整数,如果它能被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个测试的计算结果。
Input示例
545678
Output示例
30559191155
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;typedef long long LL;const int maxn = 1e6 + 20;LL a[maxn];bool judge(int X){    if(X % 7 == 0)        return true;    while(X)    {        if( X % 10 == 7)            return true;        X /= 10;    }    return false;}int main(){    //memset(a,0,sizeof(a));    for(int i = 1; i <= 1000000; i++){        a[i] = a[i-1] + (judge(i) ? 0 : (LL)i * i);        //cout << a[i] << "  ";    }    int t,x;    scanf("%d",&t);    while(t--)    {        scanf("%d",&x);        cout << a[x] << endl;    }    return 0;}


0 0
原创粉丝点击