For example, we would like to find the total number of combinations selected from 1-4 to 3, in which the result of dividing any two numbers into each other is not an integer.If you choose [2, 3, 4], you can't do it because 4 is divided by 2.Thank you for your cooperation.
python
Find the number of combinations where the result of the remainder operation is not 0
.
from ittertools import combinations
lst = [*range(1,5)]
cnt = 0
for a in combinations (lst, 3):
for bin combinations(a,2):
if not divmod (*sorted(b, reverse=True))[1]:
break
else:
cnt+=1
print(cnt)
© 2025 OneMinuteCode. All rights reserved.