[백준] #5086 배수와 약수 python

2022. 12. 31. 01:28

https://www.acmicpc.net/problem/5086

 

5086번: 배수와 약수

각 테스트 케이스마다 첫 번째 숫자가 두 번째 숫자의 약수라면 factor를, 배수라면 multiple을, 둘 다 아니라면 neither를 출력한다.

www.acmicpc.net

 

📕 설명 📕

배수와 약수의 성질을 이해하고 bool 자료형을 이용해 풀이하였다.

 

🧑🏻‍💻 나의 풀이 🧑🏻‍💻

while True:
    a, b = map(int ,input().split())
    TF_factor = True
    TF_multiple = True
    if a == 0 and b == 0:
        break
    if b % a != 0 or a >=  b:
        TF_factor = False
    if a % b != 0 or b >= a or a // b == 0:
        TF_multiple = False
    if TF_factor and not TF_multiple:
        print("factor")
    elif not TF_factor and TF_multiple:
        print("multiple")
    elif not TF_factor and not TF_multiple:
        print("neither")

 

BELATED ARTICLES

more