백준: 15128번 Congruent Numbers (Python3)
Congruent Numbers 성공다국어
2 초 | 512 MB | 1650 | 656 | 598 | 40.515% |
문제
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. Note that if q = 1, then p/1 is an integer, so any integer is a rational number.
Given two rational numbers which are the non-hypotenuse legs of a right triangle, determine if the area of that triangle is a congruent number. For the purposes of this problem, it is not necessary for the length of the hypotenuse to be a rational number.
입력
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 are the sides of a right triangle.
출력
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.
예제 입력 1
3 1 4 1
예제 출력 1
1
예제 입력 2
15 1 28 3
예제 출력 2
1
예제 입력 3
1 2 3 4
예제 출력 3
0
예제 입력 4
1 1 10 1
예제 출력 4
1
답안
1
2
3
|
p1, q1, p2, q2 = map(int, input().split())
res = p1/q1 * p2/q2 / 2
print(1 if int(res) == res else 0)
|
cs |
'공부 > 코딩테스트' 카테고리의 다른 글
백준: 15059번 Hard choice (Python3) (0) | 2022.08.06 |
---|---|
백준: 15080번 Every Second Counts (Python3) (0) | 2022.08.06 |
백준: 15439번 Vera and Outfits (Python3) (0) | 2022.08.06 |
백준: 15474번 鉛筆 (Pencils) (Python3) (0) | 2022.08.06 |
백준: 15552번 빠른 A+B (Python3) (0) | 2022.08.06 |
댓글