結果

問題 No.376 立方体のN等分 (2)
ユーザー yuki2006yuki2006
提出日時 2016-06-05 00:12:52
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 898 bytes
コンパイル時間 11,296 ms
コンパイル使用メモリ 239,788 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 08:20:15
合計ジャッジ時間 16,212 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 86 ms
5,376 KB
testcase_03 AC 94 ms
5,376 KB
testcase_04 AC 99 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 23 ms
5,376 KB
testcase_10 AC 38 ms
5,376 KB
testcase_11 AC 49 ms
5,376 KB
testcase_12 AC 62 ms
5,376 KB
testcase_13 AC 63 ms
5,376 KB
testcase_14 AC 72 ms
5,376 KB
testcase_15 AC 83 ms
5,376 KB
testcase_16 AC 183 ms
5,376 KB
testcase_17 AC 88 ms
5,376 KB
testcase_18 AC 93 ms
5,376 KB
testcase_19 AC 94 ms
5,376 KB
testcase_20 AC 97 ms
5,376 KB
testcase_21 AC 193 ms
5,376 KB
testcase_22 AC 102 ms
5,376 KB
testcase_23 AC 199 ms
5,376 KB
testcase_24 AC 198 ms
5,376 KB
testcase_25 AC 107 ms
5,376 KB
testcase_26 AC 224 ms
5,376 KB
testcase_27 AC 110 ms
5,376 KB
testcase_28 AC 112 ms
5,376 KB
testcase_29 AC 109 ms
5,376 KB
testcase_30 AC 108 ms
5,376 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 110 ms
5,376 KB
testcase_36 AC 108 ms
5,376 KB
testcase_37 AC 105 ms
5,376 KB
testcase_38 AC 104 ms
5,376 KB
testcase_39 AC 105 ms
5,376 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)
			if i * i != N {
				ans = append(ans, 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