#include <iostream>
#include <cstdio>
#include
<cstdlib>
#include <string>
#include <cmath>
#include
<cstring>
#include <algorithm>
using namespace std;
bool
pre_arry[1100];
void pre_cnt() //素数筛
{
memset(pre_arry,1,sizeof(pre_arry));
pre_arry[1] =
0;
for(int i = 2; i <= 1000; ++i)
{
if(pre_arry[i]){
for(int j = i+i; j <= 1000; j+=i)
pre_arry[j] = 0;
}
}
}
void doit(int n)
{
int sum = 0,m;
for(int i = 0; i <n;
++i)
{
scanf("%d",&m);
if(pre_arry[m])
sum += m;
}
printf("%d\n",sum);
}
int main()
{
int
n,m,result;
pre_cnt();
scanf("%d",&m);
for(int kase = 1; kase <= m;
++kase) {
scanf("%d",&n);
doit(n);
}
return
0;
}
2014-4-25 运行号:837134 素数求和,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/chdxiaoming/p/3765268.html