2019-수학-가형-홀수-27

문제

2019-수학-가형-홀수-27

풀이

from sympy import Rational, divisors
U = [1,2,3,4,5,6]

def Prob(S):
    return Rational(len(S), len(U))


def intersection(a,b):
    return set(a) & set(b)
A = [2,4,6]
ans = 0 
for m in U:
  B = divisors(m)
  if Prob(A)*Prob(B) == Prob(intersection(A,B)):
    print([m, B])
    ans+=m

ans
[2, [1, 2]]
[6, [1, 2, 3, 6]]
8