思路
C++ 代码 (题目不难,但是知识点还是有的)
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 160 * 160;
struct Abc
{
int a, b;
long double w;
bool operator< (const Abc &W)const
{
return w < W.w;
}
}abc[N];
int n, k;
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
int main()
{
cin >> n;
printf("0/1\n");
for (int i = 2; i <= n; i ++ )
for (int j = 1; j < i; j ++ )
{
int t = gcd(j, i);
abc[k].a = j / t, abc[k].b = i / t;
abc[k].w = j * 1.0 / t / (i / t);
k ++ ;
}
sort(abc, abc + k);
for (int i = 0; i < k; i ++ )
if (abc[i].w != abc[i + 1].w)
printf("%d/%d\n", abc[i].a, abc[i].b);
printf("1/1\n");
return 0;
}