結果

問題 No.1006 Share an Integer
ユーザー 小野寺健小野寺健
提出日時 2021-11-06 20:06:13
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 505 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 28,288 KB
最終ジャッジ日時 2024-04-25 08:38:51
合計ジャッジ時間 14,870 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
12,288 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 77 ms
12,288 KB
testcase_04 WA -
testcase_05 AC 76 ms
12,160 KB
testcase_06 WA -
testcase_07 AC 82 ms
12,288 KB
testcase_08 AC 79 ms
12,288 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 821 ms
21,120 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1,251 ms
25,856 KB
testcase_16 AC 607 ms
19,072 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

X = gets.to_i

d = Array.new(X+1, 1)
d[0] = 0
2.upto(X) {|i|
	if d[i] == 1 then
		d[i] = 2
		(i*i).step(X, i) {|j|
			n = 1
			k = j
			while k % i == 0 do
				n += 1
				k /= i
			end
			d[j] *= n
		}
	end
}

min = X
minpair = nil

1.upto(X/2) {|a|
	b = X - a
	v = (a - d[a] - b + d[b]).abs
	if min > v then
		min = v
		minpair = a == b ? [[a, b]] : [[a, b], [b, a]]
	elsif min == v then
		minpair << [a, b]
		minpair << [b, a] if a != b
	end
}

minpair.sort_by{|x| x[0]}.each {|a, b|
	puts "#{a} #{b}"
}
0