[파이썬][백준 5086번] 배수와 약수
1. 문제Permalink
[Bronze III] 배수와 약수 - 5086Permalink
성능 요약Permalink
메모리: 30840 KB, 시간: 72 ms
분류Permalink
사칙연산(arithmetic), 수학(math)
출처: 백준, https://https://www.acmicpc.net/
2. 해결방법 시간복잡도Permalink
- 단순 코딩 O(N)
3. 문제 해결 및 코드Permalink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
while True: | |
A, B = map(int, sys.stdin.readline().split()) | |
if A == 0 and B == 0: | |
break | |
if A % B == 0: | |
print("multiple") | |
elif B % A == 0: | |
print("factor") | |
else: | |
print("neither") |
-
주석을 참고하면서 이해를 돕습니다.Permalink
4. 알고리즘 및 해설Permalink
- while문을 통해 두 값이 0인 경우가 아닌 이상 반복문을 계속 돌린다.
- if문을 통해 3가지 경우에 따라 문제에서 제시한 결과에 맞게 출력문을 출력한다.