fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cstdint>
  6. typedef std::vector<std::uint64_t> DType;
  7. typedef std::vector<DType> RType;
  8.  
  9. RType MakeHoge(std::size_t N) {
  10. RType R;
  11. R.reserve(2500);
  12. for (std::uint64_t i = 1; i <= N; i++) {
  13. for (std::uint64_t j = 1; j <= N; j++) {
  14. double V1 = std::hypot(i, j);
  15. if (V1 == std::floor(V1) ){
  16. for (std::uint64_t k = 1; k <= N; k++) {
  17. double V2 = std::hypot(i, k);
  18. double V3 = std::hypot(j, k);
  19. if ((V2 == std::floor(V2)) && (V3 == std::floor(V3))) {
  20. R.push_back({ i,j,k });
  21. }
  22. }
  23. }
  24. }
  25. }
  26.  
  27. for (auto& o : R) {
  28. std::sort(o.begin(), o.end());
  29. }
  30. std::sort(R.begin(), R.end());
  31.  
  32. R.erase(std::unique(R.begin(), R.end()), R.end());
  33.  
  34. return R;
  35.  
  36. }
  37. bool Show(RType& R) {
  38. std::uint64_t c = 0;
  39. for (auto& oo : R) {
  40. std::cout << ++c << ':';
  41. for (auto& o : oo) {
  42. std::cout << o << ',';
  43. }
  44. std::cout << std::endl;
  45. }
  46. return true;
  47. }
  48. int main() {
  49. RType R;
  50.  
  51. R = MakeHoge(10000);
  52. Show(R);
  53.  
  54. return 0;
  55. }
  56.  
  57. /** /
  58. /** /
  59. bool Adder(DType& D, std::uint64_t R) {
  60. if (D.size() == 0)return false;
  61. D[0]++;
  62. bool C = false;
  63. for (std::size_t i = 0; i < D.size(); i++) {
  64. if (C == true) {
  65. D[i]++;
  66. C = false;
  67. }
  68.  
  69. if (D[i] >= R-1) {
  70. D[i] = 0;
  71. C = true;
  72. }else {
  73. break;
  74. }
  75. }
  76.  
  77. return C;
  78. }
  79.  
  80. /** /
  81. double Hypot3(double X, double Y, double Z) {//C++17 have default this.that is more better
  82. return sqrt(X*X + Y*Y + Z*Z);
  83. }
  84. RType SelectFor3D(const std::uint64_t& Rad) {
  85. DType D{ 0,1,1 };
  86. RType R;
  87.  
  88. for (std::size_t i = 1; i <= Rad; i++) {
  89. for (std::size_t j = 1; j <= Rad; j++) {
  90. std::uint64_t V = std::hypot(i,j);
  91. if (i*i+j*j==V*V) {
  92. for (std::size_t k = 1; k <= Rad; k++) {
  93. //std::cout << i << ',' << j << ',' << k <<" "<<'\r';
  94. double V = Hypot3(i, j, k);
  95. if (V == std::floor(V)) {
  96. R.push_back({i,j,k});
  97. }
  98.  
  99. }
  100. }
  101.  
  102. }
  103. }
  104.  
  105. for (auto& o : R) {
  106. std::sort(o.begin(), o.end());
  107. }
  108. std::sort(R.begin(), R.end());
  109.  
  110. R.erase(std::unique(R.begin(), R.end()), R.end());
  111.  
  112.  
  113.  
  114. return R;
  115. }
  116.  
  117. RType SelectFor2D(RType& D) {
  118. RType R;
  119. bool F = false;
  120. for (auto& o : D) {
  121. std::sort(o.begin(), o.end());
  122. F == false;
  123. do {
  124. double V = std::hypot(o[0], o[1]);
  125. if (V != std::floor(V)) {
  126. F = true;
  127. break;
  128. }
  129. } while (std::next_permutation(o.begin(),o.end()));
  130. if (F == false) {
  131. R.push_back(o);
  132. }
  133. }
  134. return R;
  135. }
  136.  
  137. RType MakeHoge(const std::uint64_t& Rad) {
  138. RType R;
  139. std::cout << "start 篩 by 3D" << std::endl;
  140. R = SelectFor3D(Rad);
  141. Show(R);
  142. std::cout << "start 篩 by 2D" << std::endl;
  143. R = SelectFor2D(R);
  144.  
  145. return R;
  146.  
  147. }
  148.  
  149. int main()
  150. {
  151. RType R;
  152.  
  153. R = MakeHoge(10000);
  154. Show(R);
  155.  
  156.   return 0;
  157. }
  158. */
Time limit exceeded #stdin #stdout 5s 4384KB
stdin
Standard input is empty
stdout
Standard output is empty