Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5150
The meaning of the topic is directly seeking prime numbers.
But n = 1, also belongs to the answer range!! Can only say, ever a knave ah ~~~~~
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5 using namespacestd;6 7 Const intMAXN = ++5;8 intPRIME[MAXN];9 Ten BOOLIs_prime (intx) One { A //if (x = = 1)//too many hands, no preconceived. - //return false; //the culprit who was hack. - if(x = =2) the return true; - for(inti =2; I * I <= x; i++) - { - if(x% i = =0) + return false; - } + return true; A } at - intMain () - { -memset (Prime,0,sizeof(prime)); - for(inti =1; I <= MAXN; i++) - { in if(Is_prime (i)) -Prime[i] =1; to } + - intn, data; the while(SCANF ("%d", &n)! =EOF) * { $ intsum =0;Panax Notoginseng for(inti =0; I < n; i++) - { thescanf"%d", &data); + if(Prime[data]) ASum + =data; the } +printf"%d\n", sum); - } $ return 0; $}
BestCoder24 1001.Sum sum sum (hdu 5150) Problem Solving report