結果

問題 No.375 立方体のN等分 (1)
ユーザー htensaihtensai
提出日時 2019-11-21 08:58:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 542 ms / 5,000 ms
コード長 1,334 bytes
コンパイル時間 2,480 ms
コンパイル使用メモリ 82,996 KB
実行使用メモリ 43,124 KB
最終ジャッジ日時 2024-04-17 14:36:33
合計ジャッジ時間 9,098 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
42,256 KB
testcase_01 AC 130 ms
41,920 KB
testcase_02 AC 154 ms
42,272 KB
testcase_03 AC 136 ms
42,436 KB
testcase_04 AC 126 ms
41,900 KB
testcase_05 AC 127 ms
42,352 KB
testcase_06 AC 128 ms
41,972 KB
testcase_07 AC 137 ms
42,400 KB
testcase_08 AC 176 ms
42,568 KB
testcase_09 AC 128 ms
42,528 KB
testcase_10 AC 128 ms
41,888 KB
testcase_11 AC 125 ms
42,408 KB
testcase_12 AC 121 ms
42,368 KB
testcase_13 AC 141 ms
42,544 KB
testcase_14 AC 195 ms
42,612 KB
testcase_15 AC 127 ms
42,208 KB
testcase_16 AC 130 ms
42,004 KB
testcase_17 AC 371 ms
43,124 KB
testcase_18 AC 181 ms
42,392 KB
testcase_19 AC 125 ms
42,488 KB
testcase_20 AC 127 ms
42,576 KB
testcase_21 AC 127 ms
42,424 KB
testcase_22 AC 542 ms
43,092 KB
testcase_23 AC 133 ms
42,700 KB
testcase_24 AC 138 ms
42,264 KB
testcase_25 AC 133 ms
42,728 KB
testcase_26 AC 138 ms
41,764 KB
testcase_27 AC 129 ms
42,572 KB
testcase_28 AC 137 ms
42,424 KB
testcase_29 AC 138 ms
42,444 KB
testcase_30 AC 132 ms
42,340 KB
testcase_31 AC 134 ms
42,212 KB
testcase_32 AC 138 ms
42,152 KB
testcase_33 AC 137 ms
42,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long org = n;
		HashMap<Long, Integer> map = new HashMap<>();
		for (long i = 2; i <= Math.sqrt(n); i++) {
		    while (n % i == 0) {
		        if (map.containsKey(i)) {
		            map.put(i, map.get(i) + 1);
		        } else {
		            map.put(i, 1);
		        }
		        n /= i;
		    }
		}
		if (n != 1) {
	        if (map.containsKey(n)) {
	            map.put(n, map.get(n) + 1);
	        } else {
	            map.put(n, 1);
	        }
		}
		ArrayDeque<Long> deq = new ArrayDeque<>();
		ArrayDeque<Long> next = new ArrayDeque<>();
		deq.add(1L);
		for (long x : map.keySet()) {
	       while (deq.size() > 0) {
	           long y = deq.poll();
    		   for (int i = 1; i <= map.get(x); i++) {
		           next.add(y * (long)(Math.pow(x, i)));
		       }
		       next.add(y);
		   }
		   ArrayDeque<Long> tmp = deq;
		   deq = next;
		   next = tmp;
		}
		long min = Long.MAX_VALUE;
		ArrayList<Long> list = new ArrayList<Long>(deq);
		for (long x : list) {
		    for (long y : list) {
		        if ((org / x) % y == 0) {
		            min = Math.min(min, x - 1 + y - 1 + org / x / y - 1);
		        }
		    }
		}
	    System.out.println(min + " " + (org - 1));
	}
}
0