比赛 20120302 评测结果 AAAAAAAAAAA
题目名称 法雷序列 最终得分 100
用户昵称 TBK 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2012-03-02 21:02:14
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <string>
  7. #include <iomanip>
  8. using namespace std;
  9. int a,b,c,d=1,t;
  10. struct fun
  11. {
  12. double x;
  13. int y;
  14. int z;
  15. }f[10000];
  16. int Compare( const void *elem1 , const void *elem2 )
  17. {
  18. struct fun *elem3 = (struct fun *)elem1;
  19. struct fun *elem4 = (struct fun *)elem2;
  20. return (elem3->x > elem4->x)?1:-1;
  21. }
  22. int gcd(int p,int q)
  23. {
  24. if (p==0) return q;
  25. if (q==0) return p;
  26. if (p<q)
  27. {
  28. t=p;
  29. p=q;
  30. q=t;
  31. }
  32. if (p%q==0) return q;
  33. return gcd(q,p%q);
  34. }
  35. int main(void)
  36. {
  37. freopen ("frac1.in","r",stdin);
  38. freopen ("frac1.out","w",stdout);
  39. scanf("%d",&a);
  40. if (a==0) exit(0);
  41. f[0].x=0;
  42. f[0].y=0;
  43. f[0].z=1;
  44. for (b=1;b<=a;b++)
  45. for (c=a;c>=b;c--)
  46. if (gcd(b,c)==1)
  47. {
  48. f[d].x=(double)((double)b/(double)c);
  49. f[d].y=b;
  50. f[d].z=c;
  51. d++;
  52. }
  53. qsort(f,d,sizeof(fun),Compare);
  54. for (b=0;b<d;b++) printf("%d/%d\n",f[b].y,f[b].z);
  55. fclose(stdin);
  56. fclose(stdout);
  57. return 0;
  58. }
  59.