• Home
  • About
    • Awesome soubii photo

      Awesome soubii

      초보 개발자의 공부정리용 블로그입니다. 잘못 쓰여진게 있다면 친절히 알려주세요 :)

    • Learn More
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • Posts
    • All Posts
    • All Tags
  • Projects

[Algorithm]5086 배수와 약수 By Python3

28 Aug 2020

Reading time ~1 minute

오늘의 문제

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

포인트 쳌쳌

  1. while문에서 첫번째 수(a), 두번째 수(b)를 줄마다 입력받고 a=0, b=0이 되는 순간 반복문을 종료한다.(break)
  2. a/b로 나누었을 때, b/a로 나누었을 때를 생각해본다.

풀이 코드


import sys
a = 999 #초기화
b = 999 #초기화
result = []

while True:
    a, b = map(int, sys.stdin.readline().split())
    if a == 0 and b == 0:
        print('\n'.join(result))
        break
    if a % b == 0:
        result.append('multiple')
    elif b % a == 0:
        result.append('factor')
    else:
        result.append('neither')


채점 결과

image



algorithmbojpython3 Share Tweet +1