Sum sum sum
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1033 Accepted Submission (s): 612
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
Sample Output120
Source bestcoder Round #24 Test Instructions: A number if the greatest common divisor with a nonnegative integer less than or equal to it is 1, then he is p-number, giving a subsequence, asking the sum of the p-number inside. Solving the question: Note that not only prime numbers, 1 is p-number.
#include <stdio.h>#include<iostream>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespaceStd;typedefLong LongLL;Const intN =1005;intP[n];voidinit () { for(intI=2; i<= +; i++){ if(!P[i]) { for(intj=i*i;j<= +; j+=i) {P[j]=true; } } }}intMain () {init (); intN; while(SCANF ("%d", &n)! =EOF) { intsum =0; for(intI=1; i<=n;i++){ intv; scanf ("%d",&v); if(!p[v]) sum+=v; } printf ("%d\n", sum); } return 0;}
Hdu 5150 (water problem)