Advertisement
Dani_info

csfc

Apr 12th, 2018
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8. int n;
  9. cout<<"n="; cin>>n;
  10. int v[100], k=0, ind=0;
  11. int c[100];
  12. if (n%2==0)
  13. c[ind++]=2;
  14. for (int i=3; i<=n; i+=2)
  15. v[k++]=i;
  16. for (int i=0; i<k; i++)
  17. {
  18. if (v[i]!=0)
  19. c[ind++]=v[i];
  20. for (int j=i+1; j<k; j++)
  21. {
  22. if (v[j]%v[i]==0)
  23. v[j]=0;
  24. }
  25. }
  26. for (int i=0; i<ind; i++)
  27. cout<<c[i]<<" ";
  28.  
  29. return 0;
  30. }
Advertisement
RAW Paste Data Copied
Advertisement