Problem Statement
We have two fractions: a smaller fraction N1 / D1 and a bigger fraction N2 / D2.
Your task is to find three more fractions: A/B, C/D, and E/F.
These three fractions must have three distinct values, and they must all lie strictly between N1 / D1 and N2 / D2.
All values A, B, C, D, E, F must be integers between 1 and 10^9, inclusive.
Return the int[] {A, B, C, D, E, F}. All valid solutions will be accepted.
Definition
- Class:
- ThreeFractions
- Method:
- find
- Parameters:
- int, int, int, int
- Returns:
- int[]
- Method signature:
- int[] find(int N1, int D1, int N2, int D2)
- (be sure your method is public)
Constraints
- Each number in the input will be between 1 and 5000, inclusive.
- The value of N1 / D1 will be strictly smaller than the value of N2 / D2.
Examples
1
3
2
3
Returns: {1, 2, 3, 5, 147, 233 }We are looking for three fractions between 1/3 and 2/3. The three returned fractions are 1/2 = 0.5, 3/5 = 0.6, and 147/233 = approximately 0.631.1
7
7
1
Returns: {2, 1, 5, 1, 3, 1 }We are looking for three fractions between 1/7 and 7/1. The three returned fractions are 2/1, 5/1, and 3/1.2
3
3
4
Returns: {7, 10, 71, 100, 47, 69 }