// Codeforces Round #172 (Div. 2) B Nearest Fraction
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;// change to false before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
int x = in.nextInt();
int y = in.nextInt();
int n = in.nextInt();
long a = 0;
long b = 0;
long minDistA = 1000000;
long minDistB = 1;
for (int i = 1; i <= n; i++) {
long bb = i;
long aa1 = x * bb / y;
long aa2 = aa1 + 1;
if (i == 3) {
n = n + 0;
}
long distA = Math.abs((x * bb) - (aa1 * y));
long distB = y * bb;
if (compare(distA, distB, minDistA, minDistB) < 0) {
minDistA = distA;
minDistB = distB;
a = aa1;
b = bb;
}
distA = Math.abs((x * bb) - (aa2 * y));
distB = y * bb;
if (compare(distA, distB, minDistA, minDistB) < 0) {
minDistA = distA;
minDistB = distB;
a = aa2;
b = bb;
}
}
out.println("" + a + "/" + b);
}
static long compare(long a1, long b1, long a2, long b2) {
// compare a1/b1 with a2/b2
return (a1 * b2) - (a2 * b1);
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
}
}
No comments:
Post a Comment