41 lines
1.6 KiB
Text
41 lines
1.6 KiB
Text
;Task:
|
|
Partition a positive integer '''X''' into '''N''' distinct primes.
|
|
|
|
|
|
Or, to put it in another way:
|
|
|
|
Find '''N''' unique primes such that they add up to '''X'''.
|
|
|
|
|
|
Show in the output section the sum '''X''' and the '''N''' primes in ascending order separated by plus ('''+''') signs:
|
|
<big> • </big> partition '''99809''' with 1 prime.
|
|
<big> • </big> partition '''18''' with 2 primes.
|
|
<big> • </big> partition '''19''' with 3 primes.
|
|
<big> • </big> partition '''20''' with 4 primes.
|
|
<big> • </big> partition '''2017''' with 24 primes.
|
|
<big> • </big> partition '''22699''' with 1, 2, 3, <u>and</u> 4 primes.
|
|
<big> • </big> partition '''40355''' with 3 primes.
|
|
|
|
The output could/should be shown in a format such as:
|
|
|
|
Partitioned 19 with 3 primes: 3+5+11
|
|
|
|
::* Use any spacing that may be appropriate for the display.
|
|
::* You need not validate the input(s).
|
|
::* Use the lowest primes possible; use '''18 = 5+13''', not '''18 = 7+11'''.
|
|
::* You only need to show one solution.
|
|
|
|
This task is similar to factoring an integer.
|
|
|
|
|
|
;Related tasks:
|
|
:* [[Count in factors]]
|
|
:* [[Prime decomposition]]
|
|
:* [[Factors of an integer]]
|
|
:* [[Sieve of Eratosthenes]]
|
|
:* [[Primality by trial division]]
|
|
:* [[Factors of a Mersenne number]]
|
|
:* [[Factors of a Mersenne number]]
|
|
:* [[Sequence of primes by trial division]]
|
|
<br><br>
|
|
|