#include <iostream>
#include <vector>
#include <string>
#include <tuple>
typedef std::vector < std::tuple<int, int, double>> DType;
void AddAnswer(double d, std::size_t A, std::size_t B, DType& R){
std::size_t i = 0;
for (i = 0; i < R.size(); i++){
if (std::get<2>(R[i]) == d) return;
if (std::get<2>(R[i]) > d) break;
}
for (int j = R.size(); j < i; j--){
R[j] = R[j - 1];
}
R.push_back(std::make_tuple(A, B, d));
return;
}
DType F170(std::size_t N){
DType R;
for (std::size_t i = 2; i <= N; i++){
for (std::size_t j = 1; j < i; j++){
AddAnswer(j / static_cast<double>(i), j, i, R);
}
}
for (std::size_t i = 0; i <= R.size(); i++){
for (std::size_t j = i; j < R.size(); j++){
if (std::get<2>(R[i])>std::get<2>(R[j]))std::swap(R[i], R[j]);
}
}
return R;
}
bool Show(DType& 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(){
DType R;
R = F170(3);
std::cout << "M => 3"<<std::endl;
Show(R);
R = F170(5);
std::cout << "M => 5"<<std::endl;
Show(R);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dHVwbGU+Cgp0eXBlZGVmIHN0ZDo6dmVjdG9yIDwgc3RkOjp0dXBsZTxpbnQsIGludCwgZG91YmxlPj4gRFR5cGU7Cgp2b2lkIEFkZEFuc3dlcihkb3VibGUgZCwgc3RkOjpzaXplX3QgQSwgc3RkOjpzaXplX3QgQiwgRFR5cGUmIFIpewoJc3RkOjpzaXplX3QgaSA9IDA7Cglmb3IgKGkgPSAwOyBpIDwgUi5zaXplKCk7IGkrKyl7CgkJaWYgKHN0ZDo6Z2V0PDI+KFJbaV0pID09IGQpIHJldHVybjsKCQlpZiAoc3RkOjpnZXQ8Mj4oUltpXSkgPiBkKSBicmVhazsKCX0KCglmb3IgKGludCBqID0gUi5zaXplKCk7IGogPC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