結果

問題 No.376 立方体のN等分 (2)
ユーザー yuki2006yuki2006
提出日時 2016-06-05 00:08:16
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 853 bytes
コンパイル時間 10,141 ms
コンパイル使用メモリ 236,248 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 08:18:41
合計ジャッジ時間 15,401 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 95 ms
6,940 KB
testcase_03 AC 92 ms
6,944 KB
testcase_04 AC 109 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 6 ms
6,944 KB
testcase_09 AC 25 ms
6,944 KB
testcase_10 AC 41 ms
6,940 KB
testcase_11 AC 50 ms
6,948 KB
testcase_12 AC 67 ms
6,944 KB
testcase_13 AC 70 ms
6,940 KB
testcase_14 AC 77 ms
6,940 KB
testcase_15 AC 86 ms
6,940 KB
testcase_16 AC 199 ms
6,940 KB
testcase_17 AC 96 ms
6,944 KB
testcase_18 AC 99 ms
6,940 KB
testcase_19 AC 103 ms
6,940 KB
testcase_20 AC 104 ms
6,940 KB
testcase_21 AC 213 ms
6,944 KB
testcase_22 AC 109 ms
6,940 KB
testcase_23 AC 220 ms
6,944 KB
testcase_24 AC 216 ms
6,940 KB
testcase_25 AC 112 ms
6,944 KB
testcase_26 AC 232 ms
6,940 KB
testcase_27 AC 114 ms
6,944 KB
testcase_28 AC 115 ms
6,940 KB
testcase_29 AC 114 ms
6,944 KB
testcase_30 AC 114 ms
6,944 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 115 ms
6,940 KB
testcase_36 AC 115 ms
6,944 KB
testcase_37 AC 114 ms
6,940 KB
testcase_38 AC 114 ms
6,944 KB
testcase_39 AC 114 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

func divisor(N int) []int {
	ans := make([]int, 0)

	for i := 1; i * i <= N; i++ {
		if N % i == 0 {
			ans = append(ans, i, N / i)
		}
	}
	sort.Ints(ans)
	return ans
}

func main() {
	var N int
	fmt.Scanf("%d", &N)
	mn := N
	divs := divisor(N)
	
	// オーバーフロー対策
	for i := 0; i < len(divs) && divs[i] <= 1000000 && divs[i] * divs[i] * divs[i] <= N; i++ {
		if N % divs[i] != 0 {
			continue
		}

		for j := 0; j < len(divs)&& divs[j] <= 1000000  && divs[j] * divs[j] * divs[i] <= N; j++ {
			if N % (divs[i] * divs[j]) != 0 {
				continue
			}

			k := N / (divs[i] * divs[j])
			mn = min(mn, max(0, divs[i] + divs[j] + k - 3))
		}
	}
	fmt.Println(mn, N - 1)
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}
0