본문 바로가기
백준알고리즘/정수론 및 조합론

(Python/🥉3)백준 알고리즘 5086번: 배수와 약수

by windy7271 2022. 5. 30.
728x90
반응형

문제 출처:https://www.acmicpc.net/problem/5086

 

5086번: 배수와 약수

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

www.acmicpc.net

풀이:

import sys
input = sys.stdin.readline

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')

b % a == 0 이 a 가 b 의 약수

 

a % b == 0 이 b 가 a 의 약수

반응형

댓글