#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;
}
