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