fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. // i -> sqrt(n)
  7. // i*i -> n
  8.  
  9. void factorization(int n)
  10. {
  11. for (int i = 1; i * i <= n; i++)
  12. {
  13. if (n % i == 0)
  14. {
  15. cout << i << " ";
  16. if (i * i != n)
  17. {
  18. cout << n / i << " ";
  19. }
  20. }
  21. }
  22. cout << endl;
  23. }
  24.  
  25. map<ll, int> mp;
  26. void prime_factorization(ll n)
  27. {
  28. for (ll i = 2; i * i <= n; i++)
  29. {
  30. while (n % i == 0)
  31. {
  32. n /= i;
  33. mp[i]++;
  34. }
  35. }
  36. if (n != 1)
  37. mp[n]++;
  38. }
  39.  
  40. const int sz = 1000000 + 5;
  41. bool is_prime[sz + 5];
  42.  
  43. void sieve()
  44. {
  45. for (int i = 2; i <= sz; i++)
  46. is_prime[i] = 1;
  47.  
  48. for (int i = 2; i * i <= sz; i++)
  49. {
  50. if (is_prime[i])
  51. {
  52. for (int j = i * i; j <= sz; j += i)
  53. {
  54. is_prime[j] = 0;
  55. }
  56. }
  57. }
  58. }
  59.  
  60. const int N = 10000007;
  61. int spf[N + 5];
  62.  
  63. void build_spf()
  64. {
  65. for (int i = 1; i < N; i++)
  66. spf[i] = i;
  67.  
  68. for (int i = 2; i * i < N; i++)
  69. {
  70.  
  71. if (spf[i] == i)
  72. {
  73. for (int j = i * i; j < N; j += i)
  74. {
  75. if (spf[j] == j)
  76. {
  77. spf[j] = i;
  78. }
  79. }
  80. }
  81. }
  82. }
  83.  
  84. void Fact_spf(int n)
  85. {
  86. while (n > 1)
  87. {
  88. cout << spf[n] << " ";
  89. n /= spf[n];
  90. }
  91. }
  92.  
  93. void PREMTU(string s)
  94. {
  95. sort(s.begin(), s.end());
  96.  
  97. do
  98. {
  99. cout << s << "\n";
  100. } while (next_permutation(s.begin(), s.end()));
  101. }
  102.  
  103. int main()
  104. {
  105. ios_base::sync_with_stdio(false);
  106. cin.tie(NULL);
  107. sieve();
  108. build_spf();
  109. int t = 1;
  110. // cin >> t;
  111. while (t--)
  112. {
  113. int s[4] = {1, 2, 3, 4};
  114. sort(s, s + 4);
  115.  
  116. do
  117. {
  118. for (int i = 0; i < 4; i++)
  119. {
  120. cout << s[i] << " ";
  121. }
  122. cout << endl;
  123. } while (next_permutation(s, s + 4));
  124. }
  125. return 0;
  126. }
Success #stdin #stdout 0.11s 43652KB
stdin
Standard input is empty
stdout
1 2 3 4 
1 2 4 3 
1 3 2 4 
1 3 4 2 
1 4 2 3 
1 4 3 2 
2 1 3 4 
2 1 4 3 
2 3 1 4 
2 3 4 1 
2 4 1 3 
2 4 3 1 
3 1 2 4 
3 1 4 2 
3 2 1 4 
3 2 4 1 
3 4 1 2 
3 4 2 1 
4 1 2 3 
4 1 3 2 
4 2 1 3 
4 2 3 1 
4 3 1 2 
4 3 2 1