Neighbor
Time limit1sMemory limit1024 MB
Given two fractions, reduce their positive difference and output it if the numerator is 1, otherwise output NOT NEIGHBORS.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Two fractions are called "neighbors" if the reduced positive difference between them has a numerator of 1. For example, 1/11 and 1/12 subtract to 1/132, so they are neighbors. However, 2/5 and 4/5 differ by 2/5, so they are not neighbors. Determine the "neighbor" difference between two fractions and output it, or output "NOT NEIGHBORS" if they are not neighbors.
Input
The first line contains a single positive integer n, the number of data sets. Each data set is one line with four positive integers separated by single spaces, in the order numerator, denominator, numerator, denominator.
Output
For each data set, output the positive difference between the two fractions if they are neighbors, or the phrase NOT NEIGHBORS otherwise.