結果
| 問題 |
No.1664 Unstable f(n)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-03 22:34:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,236 bytes |
| コンパイル時間 | 2,545 ms |
| コンパイル使用メモリ | 77,164 KB |
| 実行使用メモリ | 37,992 KB |
| 最終ジャッジ日時 | 2024-12-15 15:11:15 |
| 合計ジャッジ時間 | 6,305 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 WA * 2 |
ソースコード
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
No1664UnstableFn solver = new No1664UnstableFn();
solver.solve(1, in, out);
out.close();
}
static class No1664UnstableFn {
public void solve(int testNumber, FastReader in, PrintWriter out) {
long n = in.nextLong();
long ans = n;
long tmp = (long) Math.sqrt(n);
ans = Math.min(ans, tmp + 2 + (n - tmp * tmp));
for (long i = 2; i * i * i <= n; i++) {
tmp = i * i * i;
long num = 3;
long k = (long) (Math.log(n) / Math.log(i));
ans = Math.min(ans, i + k + (n - (long) Math.pow(i, k)));
// do {
// ans = Math.min(ans,i + num + (n - tmp));
// tmp*=i;
//
// } while (tmp <= n);
}
out.println(ans);
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
public String next() {
while (st == null || (!st.hasMoreElements())) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
}
}