分析:遍历一下,求个gcd即可,最后按照ans排序并去重
/*
PROB:frac1
ID:wanghan
LANG:C++
*/
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
#include "algorithm"
#include "vector"
using namespace std;
int n;
int gcd(int a,int b){
if(b==) return a;
return gcd(b,a%b);
}
struct Node{
int x,y;
double ans;
};
vector<Node> p;
bool cmp(Node a,Node b){
return a.ans<b.ans;
}
int main()
{
freopen("frac1.in","r",stdin);
freopen("frac1.out","w",stdout);
cin>>n;
for(int i=;i<=n;i++){
for(int j=min(n,i+);j<=n;j++){
int x,y;
x=i/gcd(i,j),y=j/gcd(i,j);
Node t;
t.x=x,t.y=y,t.ans=(double)x/(double)y;
p.push_back(t);
}
}
sort(p.begin(),p.end(),cmp);
cout<<p[].x<<"/"<<p[].y<<endl;
for(int i=;i<p.size();i++){
if(p[i].x==p[i-].x&&(p[i].y==p[i-].y)) continue;
cout<<p[i].x<<"/"<<p[i].y<<endl;
}
return ;
}