2019-수학-가형-홀수-10

문제

2019-수학-가형-홀수-10

풀이

from itertools import combinations 
from sympy import *
def is_coprime(x, y):
    return gcd(x, y) == 1

print(is_coprime(17, 13))
True
balls = range(2,9) 
how_many = 2

com = combinations(balls, how_many)

count = 0
total = 0
for event in com:
    print([*event, is_coprime(*event)])
    if is_coprime(*event):
        count += 1
    total +=1
Rational(count,total)    
[2, 3, True]
[2, 4, False]
[2, 5, True]
[2, 6, False]
[2, 7, True]
[2, 8, False]
[3, 4, True]
[3, 5, True]
[3, 6, False]
[3, 7, True]
[3, 8, True]
[4, 5, True]
[4, 6, False]
[4, 7, True]
[4, 8, False]
[5, 6, True]
[5, 7, True]
[5, 8, True]
[6, 7, True]
[6, 8, False]
[7, 8, True]
\[\displaystyle \frac{2}{3}\]