fork download
  1. #include <bits/stdc++.h>
  2. #define imad int main
  3. #define ull unsigned long long
  4. #define ll long long
  5. #define el endl
  6. #define pb push_back
  7. #define ppb pop_back
  8. #define all(v) v.begin(), v.end()
  9. #define nl '\n'
  10. #define IOS \
  11.   ios::sync_with_stdio(0); \
  12.   cin.tie(0); \
  13.   cout.tie(0);
  14. using namespace std;
  15.  
  16. vector<ll> getDivisors(ll n, ll &sum)
  17. {
  18. vector<ll> div;
  19. sum = 0;
  20. for (ll i = 1; i * i <= n; i++)
  21. {
  22. if (n % i == 0)
  23. {
  24. div.pb(i);
  25. sum += i;
  26. if (n / i != i)
  27. {
  28. div.pb(n / i);
  29. sum += n / i;
  30. }
  31. }
  32. }
  33. sort(all(div));
  34. return div;
  35. }
  36.  
  37. bool isPrime(int n)
  38. {
  39. if (n <= 1)
  40. return false;
  41. if (n <= 3)
  42. return true;
  43. if (n % 2 == 0 || n % 3 == 0)
  44. return false;
  45.  
  46. for (int i = 5; i * i <= n; i += 6)
  47. {
  48. if (n % i == 0 || n % (i + 2) == 0)
  49. return false;
  50. }
  51. return true;
  52. }
  53.  
  54. imad()
  55. {
  56. IOS;
  57.  
  58. ll Q = 1;
  59. cin >> Q;
  60. while (Q--)
  61. {
  62.  
  63. int n;
  64. cin >> n;
  65.  
  66. if (n <= 3)
  67. {
  68. cout << "-1" << nl;
  69. continue;
  70. }
  71. int idx = 1;
  72. int x = n;
  73.  
  74. if (n % 2 != 0)
  75. {
  76. n--;
  77. }
  78. while (n > 0)
  79. {
  80. if (!isPrime(idx * n))
  81. {
  82. cout << n << " ";
  83. n--, idx++;
  84. }
  85. else
  86. {
  87. cout << n - 1 << ' ' << n << ' ';
  88. n -= 2, idx += 2;
  89. }
  90. }
  91. if (x % 2 != 0)
  92. {
  93. cout << x;
  94. }
  95. cout << nl;
  96. }
  97. return 0;
  98. }
Success #stdin #stdout 0s 5336KB
stdin
Standard input is empty
stdout
-1