Quick Find Prime time limit: +Ms | Memory Limit:65535KB Difficulty:3
-
-
Describe
-
Now give you a positive integer n, want you to quickly find out in 2 ... N These numbers inside all the primes.
-
-
Input
-
-
give a positive integer number N (n<=2000000)
But n is 0 o'clock to end the program.
No more than 100 test data sets
-
-
Output
-
-
Outputs all primes in the 2~n range. Two numbers separated by a space
-
-
Sample input
-
-
510110
-
-
Sample output
-
-
2 3 52 3 5 72 3 5 7 11
-
-
Source
-
-
Classic Questions
-
-
Uploaded by
Passing this
The prime number hits the table. The commit starts to time out. Changed to C, it's over.
#include <iostream> #include <string.h> #include <math.h> #include <stdio.h>using namespace std ; int a[2000001];void Sushu () {int i,j;a[0]=a[1]=1;for (I=2;I<=SQRT (2000000); i++) {if (a[i]==0) {for (j=i*i;j<= 2000000;j+=i) {a[j]=1;}}} int main () {Sushu (); int N,i,time;while (scanf ("%d", &n) && N) {time=0;if (n>=2) printf ("2"); for (i=3;i<=n;i++) {if (a[i]==0)//cout<< "" <<i;printf ("%d", I);} Cout<<endl;} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Quick Find primes