ゼリー、16 14バイト
2バイトを節約してくれたDennisに感謝します!
ÆḌḊ,Ṗ߀€+U$FṂo
オンラインでお試しください!
論理説明
番号nが与えられた場合:
表現はa + borのいずれかでa × b、ここでaand bは式です。
aおよびのすべての可能な値を考慮してくださいb:
- 表現がある場合は
a + b、その後、aおよびb範囲内にあります[1 .. n-1]。
- 表現が
a × bでaありb、nより大きい適切な除数である場合1。
どちらの場合も、リスト[[<proper divisors of n larger than 1>], [1, 2, ..., n-1]]が計算され(ÆḌḊ,Ṗ)、各番号に現在のリンクをマップし߀€、正しいペアを一緒に追加し(+U$)、最小値を取得します(FṂo)。
コードの説明
ÆḌḊ,Ṗ߀€+U$FṂo Main link. Assume n = 10.
ÆḌ Proper divisors. [1,2,5]
Ḋ Ḋequeue, remove the first element. [2,5]
,Ṗ Pair with Ṗop. Auto convert n = 10 to range
[1,2,3,4,5,6,7,8,9,10] and remove the last element
10, get [1,2,3,4,5,6,7,8,9].
߀€ Apply this link over each element.
+U$ Add with the Upend of itself.
FṂ Flatten and get the Ṃinimum element.
o Logical or with n.
If the list is empty, minimum returns 0 (falsy), so logical or
convert it to n.