Advertisement
Guest User

Untitled

a guest
Sep 10th, 2015
6,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4.  
  5. #include <vector>
  6. #include <set>
  7. #include <bitset>
  8. #include <map>
  9. #include <deque>
  10. #include <string>
  11.  
  12. #include <algorithm>
  13. #include <numeric>
  14.  
  15. #include <cstdio>
  16. #include <cassert>
  17. #include <cstdlib>
  18. #include <cstring>
  19. #include <ctime>
  20. #include <cmath>
  21.  
  22. #define pb push_back
  23. #define pbk pop_back
  24. #define mp make_pair
  25. #define fs first
  26. #define sc second
  27. #define all(x) (x).begin(), (x).end()
  28. #define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
  29. #define len(a) ((int) (a).size())
  30.  
  31. #ifdef CUTEBMAING
  32. #define eprintf(...) fprintf(stderr, __VA_ARGS__)
  33. #else
  34. #define eprintf(...) 42
  35. #endif
  36.  
  37. using namespace std;
  38.  
  39. typedef long long int64;
  40. typedef long double ld;
  41. typedef unsigned long long lint;
  42.  
  43. const int inf = (1 << 30) - 1;
  44. const int64 linf = (1ll << 62) - 1;
  45.  
  46. int main() {
  47.     int n; cin >> n;
  48.     vector<int> is_prime(n + 1, true), primes;
  49.     is_prime[0] = is_prime[1] = 0;
  50.     for (int i = 2; i * i <= n; i++) {
  51.         if (is_prime[i]) {
  52.             for (int j = i * i; j <= n; j += i) {
  53.                 is_prime[j] = false;
  54.             }
  55.         }
  56.     }
  57.     vector<int> ans;
  58.     for (int i = 1; i <= n; i++) {
  59.         if (is_prime[i]) {
  60.             int q = 1;
  61.             while (q <= n / i) {
  62.                 q *= i;
  63.                 ans.push_back(q);
  64.             }
  65.         }
  66.     }
  67.     cout << len(ans) << endl;
  68.     for (int i : ans) {
  69.         printf("%d ", i);
  70.     }
  71.     puts("");
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement