USCAO:Ordered Fractions

/*
ID: Jang Lawrence
PROG: frac1
LANG: C++
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#define mp make_pair
using namespace std;
struct p
{
    int a,v;
    p(){}
    p(int x,int y){a=x,v=y;}
    void print(){printf("%d%c%d\n",a,'/',v);}
};
bool cmp(p p1,p p2){return p1.a*p2.v<p2.a*p1.v;}
int gcd(int x,int y){if(y==0) return x;return gcd(y,x%y);}
vector<p>  s;
int main()
{
  #ifndef  DEBUG
  freopen("frac1.in","r",stdin);
  freopen("frac1.out","w",stdout);
  #endif
int n;
cin>>n;
s.push_back(p(0,1));
for(int i=1;i<=n;++i)
for(int j=1;j<=i;++j)
if(gcd(j,i)!=1);
else
{
    s.push_back(p(j,i));
}
sort(s.begin(),s.end(),cmp);
for(int i=0;i<s.size();++i)
s[i].print();
    return 0;
}

你可能感兴趣的:(USCAO:Ordered Fractions)