[백준/파이썬] 16625번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 16625번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
There are two lights that blink at regular intervals. When each one blinks, it turns on and then immediately back off; they don’t toggle. They are both off at time t = 0. The first one blinks at t = p, 2p, 3p, . . . seconds; the second one blinks at t = q, 2q, 3q, . . . seconds. Once they start, they both keep blinking forever. It is very exciting to see them blink at the same time (on the same second). But your patience is going to run out eventually, in s seconds. …
입력 요약
Input consists of one line containing three space-separated integers p, q, and s. The bounds are 1 ≤ p, q ≤ 100 and 1 ≤ s ≤ 10 000. The first light blinks every p seconds, the second every q seconds. …
출력 요약
Output yes if the two lights blink on the same second between time 1 and time s, or no otherwise.
코드
import sys;read=sys.stdin.readline
p,q,s=map(int,read().split())
def gcd(a,b):
while b>0:a,b=b,a%b
return a
print('no'if p*q//gcd(p,q)>s else'yes')
설명
핵심은 구현 관점에서 There are two lights that blink at regular intervals. When each one blinks, it turns on and then immediately back off; they don’t toggle. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기