标签:
题目链接:http://acm.swust.edu.cn/problem/0491/
4
3
5
2
|
1/2
1/4
|
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #define maxn 1000010 5 using namespace std; 6 struct node{ 7 int x, y; 8 bool operator<(const node &tmp)const{ 9 if (x != tmp.x) 10 return x*tmp.y < y*tmp.x; 11 return y > tmp.y; 12 } 13 }a[maxn]; 14 int gcd(int a, int b){ 15 return !b ? a : gcd(b, a%b); 16 } 17 int main(){ 18 int n, m; 19 while (~scanf("%d%d", &n, &m)){ 20 int pos = 0; 21 //i代表分母,j代表分子 22 for (int i = 1; i <= n; i++){ 23 for (int j = 1; j < i; j++){ 24 if (i == 1 && j == 1) 25 continue; 26 if (gcd(j, i) == 1){ 27 a[pos].x = j; 28 a[pos++].y = i;// x/y 29 } 30 } 31 } 32 sort(a, a + pos); 33 printf("%d/%d\n", a[m - 1].x, a[m - 1].y); 34 } 35 return 0; 36 } 37 38 //排序也可以这么单独写,看个人习惯 39 /*int cmp(node a, node b){ 40 if (a.x == b.x) 41 return a.y > b.y; 42 return a.x*b.y < a.y*b.x; 43 }*/
标签:
原文地址:http://www.cnblogs.com/zyxStar/p/4589711.html