Sum sum sum
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 290 Accepted Submission (s): 194
Problem Descriptionwe call a positive numberXP-number If there is isn't a positive number that's less thanX and the greatest common divisor of these are numbers bigger 1.
Now is given a sequence of integers. You task is to calculate the sum of p-numbers of the sequence.
Inputthere is several test cases.
In each test case:
The first line contains a integer (1n≤1000). The second line contains N integers. each of the integers is between 1 and.
Outputfor each test case, output the sum of p-numbers of the sequence.
Sample Input35 6 7110
The difficulty of Sample Output120 is: primes[1]=1;
#include <stdio.h>#include<stdlib.h>#include<iostream>#include<algorithm>#include<math.h>#include<string.h>using namespacestd;Const intMAXN =1001;BOOLFLAG[MAXN];intPRIMES[MAXN], pi;voidgetprime_1 () {intI, J; Pi=0; memset (Flag,false,sizeof(flag)); for(i =2; i < MAXN; i++) if(!Flag[i]) {Primes[i]=1;//The prime number is identified as 1 for(j = i; J < maxn; J + =i) flag[j]=true; }}intMain () {memset (primes,0,sizeof(primes)); Getprime_1 (); primes[1]=1; intN; while(SCANF ("%d", &n)! =EOF) { Long Longans=0; intA; for(intI=0; i<n;i++) {cin>>A; if(primes[a]==1) ans+=A; } cout<<ans<<Endl; } return 0;}
HDU 5150 sum sum sum prime