Congruent Numbers
InterviewTime limit2sMemory limit512 MB
Given the two legs of a right triangle as fractions p1/q1 and p2/q2, print 1 if the triangle's area is an integer, otherwise 0.
- Level
Easy2 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
A congruent number is an integer that is the area of some right triangle whose sides all have rational length. In this problem you only look at the two legs of the right triangle, not the hypotenuse.
A rational number is a fraction where the numerator and the denominator are both integers. If , then is an integer, so every integer is a rational number.
You are given the rational lengths of the two legs of a right triangle. Determine whether the area of that triangle is a congruent number. In this problem the hypotenuse does not have to be rational.
Input
The input consists of a single test case. Your program may be run several times on different inputs.
The first line contains four integers , , , (). The numbers and are the lengths of the two legs of the right triangle.
Output
Print on a single line if the area of the triangle is an integer, and otherwise. A rational area is not enough; it has to be an integer.