标签:acm
3 5 1 2 3 4 5 8 11 12 13 14 15 16 17 18 10 21 22 23 24 25 26 27 28 29 30
10 41 52
#include <iostream> #include <cstring> #include <cmath> using namespace std; int main() { int n, m,i,j,l; int dp[1001]; memset(dp, 0, sizeof(dp)); dp[2] = 1; for (i = 2; i <= 1000; i++) { if (i % 2) dp[i] = 1; } for (j = 3; j <= sqrt(1000); j += 2) { if (dp[j]) { for (l = j * 2; l <= 1000; l += j) dp[l] = 0; } } /* for (i = 0; i <= 1000; i++) { if (dp[i]) cout << i << endl; } */ cin >> n; while (n--) { cin >> m; l = 0; for (i = 0; i < m; i++) { cin >> j; if (dp[j]) l += j; } cout << l << endl; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:acm
原文地址:http://blog.csdn.net/u011694809/article/details/48107327