Jump to content

Partition an integer x into n primes: Difference between revisions

m
→‎{{header|Phix}}: " + " output
m (Minor edit to Prolog code)
m (→‎{{header|Phix}}: " + " output)
Line 1,318:
integer {v,n} = tests[i]
object res = partition(v,n)
res = iff(res=0?"not possible":substitute(trim(sprint(res),"{}"),","," + "))
printf(1,"Partition %d into %d primes: %s\n",{v,n,res})
end for</lang>
{{out}}
<pre>
Partition 99809 into 1 primes: {99809}
Partition 18 into 2 primes: {5, + 13}
Partition 19 into 3 primes: {3, + 5, + 11}
Partition 20 into 4 primes: not possible
Partition 2017 into 24 primes: {2, + 3, + 5, + 7, + 11, + 13, + 17, + 19, + 23, + 29, + 31, + 37, + 41, + 43, + 47, + 53, + 59, + 61, + 67, + 71, + 73, + 79, + 97, + 1129}
Partition 22699 into 1 primes: {22699}
Partition 22699 into 2 primes: {2, + 22697}
Partition 22699 into 3 primes: {3, + 5, + 22691}
Partition 22699 into 4 primes: {2, + 3, + 43, + 22651}
Partition 40355 into 3 primes: {3, + 139, + 40213}
</pre>
 
7,820

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.