HDU 5150 sum sum sum prime

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): 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

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.