RosettaCodeData/Task/Partition-an-integer-x-into-n-primes/00-TASK.txt
2023-07-01 13:44:08 -04:00

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> &bull; </big> &nbsp; partition '''99809''' with 1 prime.
<big> &bull; </big> &nbsp; partition '''18''' with 2 primes.
<big> &bull; </big> &nbsp; partition '''19''' with 3 primes.
<big> &bull; </big> &nbsp; partition '''20''' with 4 primes.
<big> &bull; </big> &nbsp; partition '''2017''' with 24 primes.
<big> &bull; </big> &nbsp; partition '''22699''' with 1, 2, 3, <u>and</u> 4 primes.
<big> &bull; </big> &nbsp; partition '''40355''' with 3 primes.
The output could/should be shown in a format such as:
Partitioned 19 with 3 primes: 3+5+11
::* &nbsp; Use any spacing that may be appropriate for the display.
::* &nbsp; You need not validate the input(s).
::* &nbsp; Use the lowest primes possible; &nbsp; use &nbsp;'''18 = 5+13''', &nbsp; not &nbsp; '''18 = 7+11'''.
::* &nbsp; You only need to show one solution.
This task is similar to factoring an integer.
;Related tasks:
:* &nbsp; [[Count in factors]]
:* &nbsp; [[Prime decomposition]]
:* &nbsp; [[Factors of an integer]]
:* &nbsp; [[Sieve of Eratosthenes]]
:* &nbsp; [[Primality by trial division]]
:* &nbsp; [[Factors of a Mersenne number]]
:* &nbsp; [[Factors of a Mersenne number]]
:* &nbsp; [[Sequence of primes by trial division]]
<br><br>