1.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10408 (Farey Sequence)
*
* @author David Leib
* @author Julius Tschannerl
* @version 1.0, 03/30/2009
*
* Status : Accepted
* Runtime: 0.190
*/

import java.io.*;
import java.util.*;

public class Main {


public static void main(String... args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();

while (line != null)
{
StringTokenizer st = new StringTokenizer(line);
int n = Integer.parseInt(st.nextToken());
int number = Integer.parseInt(st.nextToken());
int count = 1;
int numn, denomn, numn_1, numn_2, denomn_1, denomn_2;

numn_1 = 1;
denomn_1 = n;
numn_2 = 0;
denomn_2 = 1;
numn = 1;
denomn = n;

while (count != number)
{
numn = ((denomn_2+n)/denomn_1)*numn_1-numn_2;
denomn = ((denomn_2+n)/denomn_1)*denomn_1-denomn_2;

numn_2 = numn_1;
denomn_2 = denomn_1;
numn_1 = numn;
denomn_1 = denomn;
count++;
}
System.out.printf("%d/%d\n", numn, denomn);

line = br.readLine();
}
System.exit(0);
}
}




2.


/**
* Angewandte Mathematik SS 09
10408 Farey Sequence
* UVa Status: Accepted
* Run Time: 0.012
* Programming Language: C
* @author Doina Logofatu logofatu@hm.edu
*/

#include <stdio.h>
#include <math.h>

int main() {

int n, k;
int i, x0, x1, x2, y0, y1, y2;


while( scanf("%d %d", &n, &k) == 2){

x0 = 0; x1 = y0 = 1; y1 = n;

for(i=0; i<k; i++){

x2 = (y0+n)/y1*x1-x0;
y2 = (y0+n)/y1*y1-y0;
x0=x1; y0 = y1;
x1 = x2; y1 = y2;

}

printf("%d/%d\n", x0, y0);

}

return 0;

}