Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #define MAX 1000000
- using namespace std;
- int v[MAX];//presupunem ... toate prime
- int main()
- {
- int i, n, j;
- cout<<"n=";
- cin>>n;
- v[0]=v[1]=1;//NEPRIME
- for(i=2; i<=sqrt(n); i++)
- {
- if(v[i]==0)//daca v[i] e prim
- {
- for(j=2; i*j<=n; j++)
- v[i*j]=1;//este neprim
- }
- }
- for(i=1; i<=n; i++)
- if(!v[i])
- cout<<i<<" ";//toate numerele prime
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement