結果
問題 | No.376 立方体のN等分 (2) |
ユーザー |
![]() |
提出日時 | 2020-02-07 08:32:37 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,967 ms / 5,000 ms |
コード長 | 1,098 bytes |
コンパイル時間 | 3,631 ms |
コンパイル使用メモリ | 79,184 KB |
実行使用メモリ | 55,896 KB |
最終ジャッジ日時 | 2024-09-25 07:12:45 |
合計ジャッジ時間 | 20,317 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); long n = Long.parseLong(br.readLine()); TreeSet<Long> set = new TreeSet<>(); for (long i = 1; i <= Math.sqrt(n); i++) { if (n % i == 0) { set.add(i); set.add(n / i); } } long min = Long.MAX_VALUE; for (long x : set) { if (x > Math.sqrt(n)) { break; } for (long y : set) { if (y > Math.sqrt(n)) { break; } if (x * y > n) { break; } if (x > y) { continue; } if ((n / x) % y != 0) { continue; } min = Math.min(min, x + y + n / x / y - 3); } } System.out.println(min + " " + (n - 1)); } }