fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. #define OO INT_MAX/10
  5. #define PB push_back
  6. #define MP make_pair
  7. #define MOD 1000000007
  8. #define EPS 1e-9
  9. #define endl "\n"
  10. #define all(v) (v).begin(),(v).end()
  11.  
  12. typedef long long int ll;
  13. typedef pair<int,int> ii;
  14. typedef vector <int>vi;
  15. typedef vector <ii>vii;
  16. typedef vector<vi> vvi;
  17. typedef vector<vii>vvii;
  18.  
  19. void read()
  20. {
  21. #ifdef OR_WORKSTATION
  22. freopen("in.in","rt",stdin);
  23. freopen("outt.out","wt",stdout);
  24. #endif
  25. }
  26.  
  27. vector<bool>a;
  28. vi primes;
  29. void sieve ()
  30. {
  31. int n=1500;
  32. a.assign(n,1);
  33. a[0]=0;
  34. a[1]=0;
  35. for(int i=2;i<1500;i++)
  36. {
  37. if(a[i])
  38. {
  39. for(int j=i*i;j<n;j+=i)
  40. a[j]=0;
  41. primes.PB(i);
  42. }
  43.  
  44. }
  45.  
  46. }
  47.  
  48. int main()
  49. {
  50. read();
  51. sieve();
  52. int n;
  53. while(cin>>n)
  54. {
  55. vi v;
  56. for(int i=0;i<=169;i++)
  57. {
  58. int tmp=primes[i];
  59. if(tmp>n)
  60. break;
  61. int cnt=1;
  62. while(1)
  63. {
  64. tmp=pow(primes[i],cnt++);
  65. if(tmp>n)
  66. break;
  67. v.PB(tmp);
  68. }
  69. }
  70. int l=v.size();
  71. cout<<l<<endl;
  72. for(int i=0;i<l;i++)
  73. cout<<v[i]<<" ";
  74. cout<<endl;
  75. }
  76.  
  77.  
  78. }
Success #stdin #stdout 0s 2868KB
stdin
15
stdout
9
2 4 8 3 9 5 7 11 13