Baekjoon/단계별로 풀어보기

[백준][9단계 약수,배수와 소수] 5086번 /배수와 약수 (파이썬/Python)

junslee 2025. 4. 5. 16:10

1. 문제 설명

2. 코드

while True:
    a,b = map(int,input().split())
    if a==0 and b==0:
        break
    if b%a == 0:
        print("factor")
    elif a%b == 0:
        print("multiple")
    else:
        print("neither")

3. 풀이 과정

무한 반복 조건문을 만들기 위해 while에 True 조건을 넣는다.

a,b를 정수로 입력받는다.

a와b가 0이면 break로 while문을 빠져나온다.

a가 b의 약수인 경우 b%a==0이면 "factor"를 출력한다.

a가 b의 배수인 경우 a%b==0이면 "multiple"를 출력한다.

둘 다 아닌 경우 "neither"를 출력한다.