题解 | #游游的数值距离#
游游的数值距离
https://www.nowcoder.com/practice/a3688c3615d144e4ba79357034850e3c
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
static void solve() {
long n = in.nextLong();
long a = 0, b = 0;
if (n <= 2) {
out.println("1 1");
} else if (n == 3 || n == 4) {
out.println("3 1");
} else {
long ft = 2, mi = Long.MAX_VALUE;
for (long i = 3; i <= 13; i++) {
ft *= i;
long now = ft - 1;
long t = n / now;
if ((n - now * t) < mi && t != 2 && t != 0) {
a = i;
b = t;
mi = n - now * t;
}
if(now*(t+1)-n<mi&&t!=1&&t!=0) {
a = i;
b = t + 1;
mi = now*(t+1)-n;
}
}
out.println(a+" "+b);
}
}
public static void main(String[] args) {
solve();
out.flush();
}
static FastReader in = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
static class FastReader {
static BufferedReader br;
static StringTokenizer st;
FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
String str = "";
while (st == null || !st.hasMoreElements()) {
try {
str = br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
st = new StringTokenizer(str);
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}
