您的位置:首页 > 其它

51nod 1082 与7无关的数

2018-03-12 19:20 211 查看
原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1082
思路:O(n)打表,O(1)查询即可。
AC代码:#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1000005;
long long a[MAXN], t, n;

void preProcess() {
a[1] = 1;
for (int i = 2; i <= 1000000; i++) {
a[i] = a[i - 1];
bool flag = false;
if (i % 7 == 0) {
flag = true;
}
else {
int t = i;
while (t) {
if (t % 10 == 7) {
flag = true;
break;
}
t /= 10;
}
}
if (!flag)a[i] += 1LL * i*i;
}
}
int main() {
preProcess();
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
printf("%lld\n", a
);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: