# PROBLEM LINK:

Contest Division 1

Contest Division 2

Contest Division 3

Contest Division 4

Setter: Tejas Pandey

Tester: Nishank Suresh, Utkarsh Gupta

Editorialist: Pratiyush Mishra

# DIFFICULTY:

1713

# PREREQUISITES:

None

# PROBLEM:

A *segment* is a range of **non-negative** integers L, L + 1, L + 2, \ldots, R, denoted [L, R] where L \leq R.

Chef has a set S consisting of **all** segments [L, R] such that either L + R = X or L\cdot R = Y.

For example, if X = 5 and Y = 6, then Chef’s set is S = \{[0, 5], [1, 4], [1, 6], [2, 3]\}.

Given the integers X and Y, can you help Chef find two non-intersecting segments from his set S? If it is not possible to find two such non-intersecting segments, print -1. If there are multiple possible answers, you may output **any** of them.

**Note:** Two segments are said to be non-intersecting if they have no number in common. For example, [1, 4] and [10, 42] are non-intersecting, while [1, 4] and [4, 6] are not since they have 4 in common.

# EXPLANATION:

**Observation 1**: The smallest interval [L,R] such that L+R = X would be:

Any other interval would overlap the above one.

So we can choose one of the intervals as above and then loop through all possible intervals such that L \times R = Y and for each interval we check if the two intersect each other or not.

# TIME COMPLEXITY:

O(\sqrt{N}), for each test case.

# SOLUTION:

Editorialist’s Solution

Setter’s Solution

Tester1’s Solution

Tester2’s Solution