fork download
  1. // In the name of God
  2. #include <iostream>
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <algorithm>
  7. #include <iomanip>
  8. #include <ctime>
  9. #include <queue>
  10. #include <set>
  11. #include <map>
  12. #include <vector>
  13. #include <list>
  14. #include <assert.h>
  15. #include <bitset>
  16. #include <unordered_set>
  17. #define sqr(a) ((a)*(a))
  18. #define all(a) (a).begin(), (a).end()
  19. using namespace std;
  20.  
  21. template <typename T>
  22. T next_int() {
  23. T x = 0, p = 1;
  24. char ch;
  25. do { ch = getchar(); } while(ch <= ' ');
  26. if(ch == '-') {
  27. p = -1;
  28. ch = getchar();
  29. }
  30. while(ch >= '0' && ch <= '9') {
  31. x = x * 10 + (ch - '0');
  32. ch = getchar();
  33. }
  34. return p * x;
  35. }
  36.  
  37. string next_token() {
  38. char ch;
  39. string ans = "";
  40. do { ch = getchar(); } while(ch <= ' ');
  41. while(ch > ' ') {
  42. ans += ch;
  43. ch = getchar();
  44. }
  45. return ans;
  46. }
  47.  
  48. const long long INF = (long long)1e18 + 227 + 1;
  49. const int INFINT = 1e9 + 227 + 1;
  50. const int MAXN = (int)1e6 + 227 + 1;
  51. const int MOD = (int)1e9 + 7;
  52. const long double EPS = 1e-9;
  53.  
  54. long long bin_pow(long long a, long long b) {
  55. if(!b) return 1;
  56. long long ans = bin_pow(a, b / 2);
  57. ans = ans * ans % MOD;
  58. if(b % 2) ans = ans * a % MOD;
  59. return ans;
  60. }
  61.  
  62. vector<long long> prime;
  63. bool used[MAXN];
  64.  
  65. void build_prime() {
  66. for(int i = 2; i < MAXN; i++) {
  67. if(used[i]) continue;
  68. prime.push_back(i);
  69. for(int j = i; j < MAXN; j += i)
  70. used[j] = 1;
  71. }
  72. }
  73.  
  74. int main() {
  75. freopen(".in", "w", stdout);
  76.  
  77. build_prime();
  78.  
  79. int mx = -INFINT, p = -1;
  80. for(int l = 0; l + 1 < 1000; l++) {
  81. int k = 0;
  82. for(int r = l; r < prime.size(); r++) {
  83. if(prime[r] >= min((long long)1e6, prime[l] * prime[l + 1] - 1))
  84. break;
  85. k++;
  86. }
  87.  
  88. if(k > mx) {
  89. mx = k;
  90. p = l;
  91. }
  92. }
  93.  
  94. vector<int> ans;
  95.  
  96. int l = p;
  97. for(int r = l; r < prime.size(); r++) {
  98. if(prime[r] >= min((long long)1e6, prime[l] * prime[l + 1] - 1))
  99. break;
  100. ans.push_back(prime[r]);
  101. }
  102.  
  103. ans.push_back(min((long long)1e6, prime[l] * prime[l + 1] - 1));
  104. ans.push_back(min((long long)1e6, prime[l] * prime[l + 1] - 1));
  105.  
  106. cout << ans.size() << "\n";
  107. for(int i = 0; i < ans.size(); i++)
  108. cout << ans[i] << " ";
  109. puts("");
  110. }
  111.  
Success #stdin #stdout 0.07s 4444KB
stdin
Standard input is empty
stdout
Standard output is empty