比赛 20120302 评测结果 AAAAAAAAAAA
题目名称 法雷序列 最终得分 100
用户昵称 TBK 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2012-03-02 21:02:14
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
using namespace std;
int a,b,c,d=1,t;
struct fun
{
	double x;
	int y;
	int z;
}f[10000];
int Compare( const void *elem1 , const void *elem2 )
{
	struct fun *elem3 = (struct fun *)elem1;
	struct fun *elem4 = (struct fun *)elem2;
	return (elem3->x > elem4->x)?1:-1;
}
int gcd(int p,int q)
{
	if (p==0) return q;
	if (q==0) return p;
	if (p<q)
	{
		t=p;
		p=q;
		q=t;
	}
	if (p%q==0) return q;
	return gcd(q,p%q);
}
int main(void)
{
	freopen ("frac1.in","r",stdin);
	freopen ("frac1.out","w",stdout);
	scanf("%d",&a);
	if (a==0) exit(0);	
	f[0].x=0;
	f[0].y=0;
	f[0].z=1;
	for (b=1;b<=a;b++)
		for (c=a;c>=b;c--)
			if (gcd(b,c)==1)
			{
				f[d].x=(double)((double)b/(double)c);
				f[d].y=b;
				f[d].z=c;
				d++;
			}
	qsort(f,d,sizeof(fun),Compare);
	for (b=0;b<d;b++) printf("%d/%d\n",f[b].y,f[b].z);
	fclose(stdin);
	fclose(stdout);
	return 0;
}