1706 Seeking composite and

Source: Internet
Author: User

1706 seeking composite and

time limit: 1 sspace limit: 128000 KBtitle level: Silver SolvingView Run ResultsTitle Description Description

The user enters a number, and then outputs all the composite from 1 onwards to this number (including this number).

Enter a description Input Description

An integer n,0<n<=1000

Output description Output Description

A line, an integer, that is, from 1 to n all composite and

Sample input Sample Input

Example one: 100

Sample two: 9

Sample output Sample Output

Example one: 3989

Sample two: 27

Data range and Tips Data Size & Hint

First the prime number is found, and then the sum is not the prime number.

#include <cstdio>#include<cstring>#include<iostream>using namespacestd;#defineN 10010intPrime[n];BOOLCheck[n];intMain () {memset (check,0,sizeofcheck); inttot=0; intn,sum=0; scanf ("%d",&N);  for(intI=2; i<=n;i++){       if(!Check[i]) Prime[tot++]=i;  for(intj=0; j<tot;j++){            if(i*prime[j]>n) Break; Check[i*prime[j]]=1; if(i%prime[j]==0) Break; }      }     for(intI=2; i<=n;i++)        if(Check[i]) sum+=i; printf ("%d\n", sum); return 0;}

1706 Seeking composite and

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.