fork download
  1. // div22.cpp : Defines the entry point for the console application.
  2. //
  3. #include <iostream>
  4. #include <cstdint>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. typedef std::vector<std::uint64_t> DType;
  9. typedef std::vector<DType> RType;
  10. bool Adder(DType& D, std::uint64_t R) {
  11. if (D.size() == 0)return false;
  12. D[0]++;
  13. bool F = false;
  14. for (std::size_t i = 0; i < D.size(); i++) {
  15. if (F == true) {
  16. D[i]++;
  17. F = false;
  18. }
  19. F = false;
  20. if (D[i] >= R) {
  21. D[i] = 0;
  22. F = true;
  23. }else{
  24. break;
  25. }
  26. }
  27. return F;
  28. }
  29.  
  30. RType MakeHoge(std::uint64_t N) {
  31. if (N == 0)return RType();
  32. DType D(2);
  33. std::uint64_t C=0;
  34. RType R;
  35. double I = 0;
  36. std::uint64_t V = 0;
  37. while (D.size()!=N+1) {
  38. L:
  39. if (Adder(D, N - (D.size()-1)) == true) {
  40. D.push_back(0);
  41. continue;
  42. }
  43. C = 0;
  44. //std::cout << N - (D.size() - 1) <<' '<< V++ << "\r";
  45. for (auto& o : D) {
  46. C += o;
  47. if (C > N)goto L;
  48. }
  49. I = 0;
  50. for (auto& o : D) {
  51. if (o == 0)continue;
  52. I += (1.0 / o);
  53. }
  54. if (I == 1.0)R.push_back(D);
  55. }
  56.  
  57. for (auto& o : R) {
  58. for (std::size_t i = o.size(); i < N; i++)o.push_back(0);
  59. std::sort(o.begin(), o.end());
  60. }
  61. std::sort(R.begin(), R.end());
  62. R.erase(std::unique(R.begin(), R.end()), R.end());
  63.  
  64.  
  65. return R;
  66.  
  67. }
  68.  
  69. bool Show(const RType& R) {
  70. for (auto& oo : R) {
  71. for (auto& o : oo) {
  72. if (o == 0)continue;
  73. std::cout << o << ',';
  74. }
  75. std::cout << std::endl;
  76. }
  77. return true;
  78. }
  79.  
  80. int main()
  81. {
  82. RType R;
  83.  
  84. R = MakeHoge(22);
  85. Show(R);
  86. return 0;
  87. }
Time limit exceeded #stdin #stdout 5s 4588KB
stdin
Standard input is empty
stdout
Standard output is empty