For each element of a combination, please tell us a program that takes any two numbers that are included and divides one by the other to determine the total number of combinations that do not become integers.

Asked 1 years ago, Updated 1 years ago, 275 views

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

2022-12-19 00:59

1 Answers

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)  


2022-12-19 09:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.