# How can I reduce the time to compile this solve?

I want to find five integer numbers $$a, b, c, d, e$$ so that $$a+ b+ c + d + e = 9 k$$ and none of two number in which are equal. I tried.

    {a, b, c, d, e, k} /.
Solve[{a + b + c + d + e == 9 k, 0 <= a <= 9, 0 <= b <= 9,
0 <= c <= 9, 0 <= d <= 9, 0 <= e <= 9,
1 <= k <=
5, (a - b) (a - c) (a - d) (a - e) (b - c) (b - d) (b - e) (c - d) (c - e) (d - e) != 0}, {a, b, c, d, e, k}, Integers]


For a long time, I can not get the result. How can I get the result?

 SolveValues[{a + b + c + d + e == 9 k, 0 <= a < b < c < d < e <= 9,
1 <= k <= 5}, {a, b, c, d, e, k}, Integers]


• You don't need the 1 <= k <= 5 constraint: SolveValues[{a + b + c + d + e == 9 k, 0 <= a < b < c < d < e <= 9}, {a, b, c, d, e, k}, Integers] will do just fine. Commented Apr 16, 2023 at 8:08
• @Roman Thank you! Commented Apr 16, 2023 at 8:44

For versions prior to v12.3 that don't feature the SolveValues command, you can use the FindInstance command. This will find 10 instances over the domain of PositiveIntegers.

FindInstance[
a + b + c + d + e == 9 k && 1 <= k <= 5 &&
UnsameQ[a, b, c, d, e], {a, b, c, d, e, k}, PositiveIntegers, 10]


{{a -> 1, b -> 3, c -> 3, d -> 1, e -> 28, k -> 4}, {a -> 6, b -> 30, c -> 6, d -> 2, e -> 1, k -> 5}, {a -> 2, b -> 3, c -> 4, d -> 13,
e -> 23, k -> 5}, {a -> 1, b -> 2, c -> 4, d -> 2, e -> 18, k -> 3}, {a -> 3, b -> 2, c -> 3, d -> 1, e -> 9, k -> 2}, {a -> 5, b -> 1, c -> 1, d -> 2, e -> 36, k -> 5}, {a -> 7, b -> 1, c -> 2, d -> 13, e -> 22, k -> 5}, {a -> 1, b -> 3, c -> 2, d -> 37, e -> 2, k -> 5}, {a -> 3, b -> 2, c -> 1, d -> 1, e -> 20, k -> 3}, {a -> 6, b -> 2, c -> 5, d -> 5, e -> 27, k -> 5}}

Essentially you want IntegerPartitions of {9, 18, 27, 36, 45} such that all integers in the set are unique. To get the complete list:

pall = (IntegerPartitions[9 #, {5}] & /@ Range[5]);
Pick[pall, Map[Apply[UnsameQ][#] &, pall, {2}]]


No luck with 9 as 1+2+3+4 would be 10. You can get the same result with:

Pick[pall, Map[DuplicateFreeQ, pall, {2}]]