結果

問題 No.376 立方体のN等分 (2)
ユーザー htensaihtensai
提出日時 2019-11-21 08:59:12
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,334 bytes
コンパイル時間 3,147 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 49,076 KB
最終ジャッジ日時 2024-04-17 14:38:57
合計ジャッジ時間 13,398 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 172 ms
47,836 KB
testcase_01 AC 178 ms
42,588 KB
testcase_02 AC 170 ms
42,704 KB
testcase_03 AC 196 ms
42,388 KB
testcase_04 AC 168 ms
42,388 KB
testcase_05 AC 164 ms
42,224 KB
testcase_06 AC 150 ms
41,620 KB
testcase_07 AC 163 ms
42,180 KB
testcase_08 AC 178 ms
42,704 KB
testcase_09 AC 164 ms
42,416 KB
testcase_10 AC 646 ms
43,008 KB
testcase_11 AC 178 ms
42,448 KB
testcase_12 AC 159 ms
42,320 KB
testcase_13 AC 167 ms
42,256 KB
testcase_14 AC 167 ms
42,060 KB
testcase_15 AC 184 ms
42,604 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

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