fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <algorithm>
  5. #include <tuple>
  6.  
  7. //you CAN'T modify this code.copyright by Yakitori@2014
  8. //このコード片の一部でも流用したら訴訟します。以上。
  9. //no one can get any lisence to this code.
  10. //誰にもライセンスいたしません。
  11.  
  12. std::int64_t gcd(std::int64_t M, std::int64_t N){
  13.  
  14. if (std::abs(M) < std::abs(N)) std::swap(M, N);
  15.  
  16. if (N == 0) return M;
  17. return gcd(N, M%N);
  18. }
  19.  
  20. std::vector<std::tuple<int, int, double>> MakeHoge(std::size_t M){
  21. std::vector<std::tuple<int, int, double>> ret;
  22. for (std::size_t i = 1; i <= M; i++){
  23. for (std::size_t j = 1; j < M; j++){
  24. auto Tup = std::make_tuple(j, i, j / static_cast<double>(i));
  25. if (std::get<2>(Tup) >= 1)continue;
  26. if (gcd(i, j) != 1) continue;
  27. ret.push_back(Tup);
  28. }
  29. }
  30. double A = 0;
  31. double B = 0;
  32. for (std::size_t i = 0; i < ret.size(); i++){//渾身のバブルソート。コムソート調べるの面倒。
  33. for (std::size_t j = i + 1; j < ret.size(); j++){
  34. if (std::get<2>(ret[i])> std::get<2>(ret[j])){
  35. std::swap(ret[i], ret[j]);
  36. }
  37. }
  38. }
  39.  
  40. return ret;
  41. }
  42.  
  43. bool Show(std::vector<std::tuple<int, int, double>>& vec){
  44.  
  45. for (auto&o : vec){
  46. std::cout << std::get<0>(o) << '/' << std::get<1>(o) << "=" << std::get<2>(o) << std::endl;
  47. }
  48.  
  49. return true;
  50.  
  51. }
  52.  
  53. int main(){
  54. //auto A = gcd(1071, 1029);
  55. //auto B = gcd(4, 5);
  56. std::vector<std::tuple<int, int, double>> R;
  57. int M = 0;
  58.  
  59. M = 3;
  60. R = MakeHoge(M);
  61. std::cout << "M => " << M << std::endl;
  62. Show(R);
  63.  
  64.  
  65. M = 5;
  66. auto R2 = MakeHoge(M);
  67. std::cout << "M => " << M << std::endl;
  68. Show(R2);
  69. return 0;
  70. }
  71.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
M => 3
1/3=0.333333
1/2=0.5
2/3=0.666667
M => 5
1/5=0.2
1/4=0.25
1/3=0.333333
2/5=0.4
1/2=0.5
3/5=0.6
2/3=0.666667
3/4=0.75
4/5=0.8