本文主要是介绍hdu 5150 sum sum sum,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:hdu 5150 sum sum sum
1不是p-number
#include <cstdio>
#include <cstring>
#include <algorithm>using namespace std;
typedef long long ll;const int maxn = 1000;
int vis[maxn + 5];void init (int n) {memset(vis, 0, sizeof(vis));vis[1] = 0;for (int i = 2; i <= n; i++) {if (vis[i])continue;for (int j = i * i; j <= n; j += i)vis[j] = 1;}
}int main () {init(maxn);int n;while (scanf("%d", &n) == 1) {int ans = 0, x;for (int i = 0; i < n; i++) {scanf("%d", &x);if (vis[x] == 0)ans += x;}printf("%d\n", ans);}return 0;
}
这篇关于hdu 5150 sum sum sum的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!