[백준/파이썬] 15128번 풀이

업데이트:



문제 정보


풀이

문제

A congruent number is an integer that is the area of some right triangle where the length of each side of the triangle is a rational number. For this problem, we’ll only consider the legs of the right triangle, and not the hypotenuse.

A rational number is a fraction, p/q, where p, the numerator, and q, the denominator, are integers. …

입력 요약
Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will consist of a single line with four integers p1, q1, p2 and q2 (1 ≤ p1,q1,p2,q2 ≤ 100,000) where p1/q1 and p2/q2 are the rational numbers which …

출력 요약
Output a single integer, which is 1 if the area of the triangle is an integer, 0 if not. Note that the area has to be an integer, not just a rational number.

코드

a,b,c,d=map(int,input().split())
print(1 if a*c%(b*d*2)==0 else 0)

설명

핵심은 구현 관점에서 A congruent number is an integer that is the area of some right triangle where the length of each side of the triangle is a rational number. …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기