fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <math.h>
  5. #include <algorithm>
  6.  
  7. typedef std::vector<std::uint64_t> DType;
  8. //typedef std::pair<DType, double> RType;
  9. typedef std::pair<DType, std::uint64_t> RType;
  10. DType MakePrime(std::uint64_t N){
  11. DType R;
  12. R.push_back(2);
  13. bool F = false;
  14.  
  15. for (std::size_t i = 3; i <= N; i++)
  16. {
  17. F = true;
  18. for (auto o : R){
  19. if (i%o == 0){
  20. F = false;
  21. break;
  22. }
  23. }
  24. if (F == true) R.push_back(i);
  25.  
  26. }
  27. return R;
  28. }
  29. DType MnipArray2(DType D){
  30. std::uint64_t N = D.back();
  31. D.pop_back();
  32. D[0] += N;
  33.  
  34. return D;
  35. }
  36. DType MnipArray(DType D){
  37. std::uint64_t N = D.back();
  38. D.pop_back();
  39. for (std::size_t i = 0; i < N; i++)
  40. {
  41. D[i%D.size()]++;
  42. }
  43.  
  44. return D;
  45. }
  46.  
  47. std::size_t FindFirstMinnestIndex(DType& D){
  48.  
  49. std::size_t Idx = 0;
  50. std::uint64_t V = D[0];
  51. for (std::size_t i = 0; i < D.size(); i++)
  52. {
  53. if (D[i]<V){
  54. Idx = i;
  55. V = D[i];
  56. }
  57. }
  58. return Idx;
  59. }
  60.  
  61. DType MnipArray3(DType D){
  62. std::uint64_t N = D.back();
  63. D.pop_back();
  64. bool F = false;;
  65. std::size_t Idx = FindFirstMinnestIndex(D);
  66.  
  67. for (std::size_t i = 0; i < N; i++)
  68. {
  69. D[(Idx + i) % D.size()]++;
  70. }
  71.  
  72. return D;
  73. }
  74. RType MakeHoge(std::uint64_t N){
  75. std::int64_t X = N;
  76. auto P = MakePrime(static_cast<std::uint64_t>(X));//<- not need??
  77. DType R;
  78. double RD = 1;
  79. //std::uint64_t RD = 1;
  80.  
  81. DType T;
  82. double TD = 1;
  83. std::uint64_t A = 0;
  84. std::uint64_t B = 0;
  85.  
  86. while (X>1){
  87. for (auto o : P){
  88. if (X - o > 1){
  89. X -= o;
  90. R.push_back(o);
  91. break;
  92. }
  93.  
  94. }
  95. }
  96. if (X != 0) R.back() += X;
  97. std::swap(R[0], R.back());
  98.  
  99. T = R;
  100.  
  101. while (T.size() > 2){
  102. TD = 1;
  103. for (auto o : T) TD *= o;
  104. if (TD > RD){
  105. RD = TD;
  106. R = T;
  107. }
  108. //std::reverse(T.begin(), T.end());
  109. //std::swap(T[0], T.back());
  110. T = MnipArray3(T);
  111.  
  112. }
  113. return std::make_pair(R,RD);
  114. }
  115.  
  116. bool Show(RType& D){
  117.  
  118. std::cout << D.second << "@" << D.first.size() << "Count!" << std::endl;
  119. std::cout << "Result:" << std::endl;
  120. for (auto o : D.first) std::cout << o << ',';
  121. std::cout << std::endl;
  122. return true;
  123.  
  124. }
  125.  
  126. int main(){
  127.  
  128. RType R;
  129.  
  130. R=MakeHoge(10);
  131. Show(R);
  132. R=MakeHoge(64);
  133. Show(R);
  134. R=MakeHoge(100);
  135. Show(R);
  136. return 0;
  137. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
36@4Count!
Result:
3,3,2,2,
13947137604@22Count!
Result:
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,
7412080755407364@34Count!
Result:
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,