#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
#include <tuple>
//you CAN'T modify this code.copyright by Yakitori@2014
//このコード片の一部でも流用したら訴訟します。以上。
//no one can get any lisence to this code.
//誰にもライセンスいたしません。
std::int64_t gcd(std::int64_t M, std::int64_t N){
if (std::abs(M) < std::abs(N)) std::swap(M, N);
if (N == 0) return M;
return gcd(N, M%N);
}
std::vector<std::tuple<int, int, double>> MakeHoge(std::size_t M){
std::vector<std::tuple<int, int, double>> ret;
for (std::size_t i = 1; i <= M; i++){
for (std::size_t j = 1; j < M; j++){
auto Tup = std::make_tuple(j, i, j / static_cast<double>(i));
if (std::get<2>(Tup) >= 1)continue;
if (gcd(i, j) != 1) continue;
ret.push_back(Tup);
}
}
double A = 0;
double B = 0;
for (std::size_t i = 0; i < ret.size(); i++){//渾身のバブルソート。コムソート調べるの面倒。
for (std::size_t j = i + 1; j < ret.size(); j++){
if (std::get<2>(ret[i])> std::get<2>(ret[j])){
std::swap(ret[i], ret[j]);
}
}
}
return ret;
}
bool Show(std::vector<std::tuple<int, int, double>>& vec){
for (auto&o : vec){
std::cout << std::get<0>(o) << '/' << std::get<1>(o) << "=" << std::get<2>(o) << std::endl;
}
return true;
}
int main(){
//auto A = gcd(1071, 1029);
//auto B = gcd(4, 5);
std::vector<std::tuple<int, int, double>> R;
int M = 0;
M = 3;
R = MakeHoge(M);
std::cout << "M => " << M << std::endl;
Show(R);
M = 5;
auto R2 = MakeHoge(M);
std::cout << "M => " << M << std::endl;
Show(R2);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0ZGludD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHR1cGxlPgoKLy95b3UgQ0FOJ1QgbW9kaWZ5IHRoaXMgY29kZS5jb3B5cmlnaHQgYnkgWWFraXRvcmlAMjAxNAovL+OBk+OBruOCs+ODvOODieeJh+OBruS4gOmDqOOBp+O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