-
Notifications
You must be signed in to change notification settings - Fork 0
/
10408.cpp
60 lines (40 loc) · 952 Bytes
/
10408.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#define MAXN 1000000
using namespace std;
int n, k, cnt;
struct state {
int a, b;
};
bool operator <( const state &a, const state &b ) {
return ( a.a * b.b < b.a * a.b );
}
state A[MAXN+1];
int gcd( int a, int b ) {
if ( b == 0 ) {
return ( a );
}
return ( gcd( b, a % b ) );
}
int main( ) {
while( scanf( "%d %d", &n, &k ) != EOF ) {
cnt = 0;
A[0].a = 1;
A[0].b = 1;
for ( int i = 1; i <= n; ++i ) {
for ( int j = i+1; j <= n; ++j ) {
if ( gcd( i, j ) == 1 ) {
++cnt;
A[cnt].a = i;
A[cnt].b = j;
}
}
}
sort( A, A+cnt+1 );
printf( "%d/%d\n", A[k-1].a, A[k-1].b );
}
return 0;
}