Hdu 5150 (water problem)

Source: Internet
Author: User
Tags greatest common divisor

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.