This page is still under construction.

Parts of this page are still being built. What you see may change.

Number

Time limit2sMemory limit1024 MB

Summary
Given ranges [a,b] and [c,d], find the smallest integer greater than ac that is not a product u*v with u in [a,b] and v in [c,d].
Level

Hard8 of 10

Topics
Math, Number theory, Binary search, Greedy
Solved
No attempts yet

Problem

Given natural numbers aa, bb, cc, and dd, find the smallest natural number nn greater than acac that cannot be written as the product of two natural numbers uu and vv with a≤u≤ba \le u \le b and c≤v≤dc \le v \le d.

Input

The input file contains a single line with the natural numbers aa, bb, cc, and dd (1≤a≤b≤1061 \le a \le b \le 10^6, 1≤c≤d≤1061 \le c \le d \le 10^6).

Output

Print the number nn.

Examples2

  1. Example 1

    Input
    1 2 1 2
    
    Expected output
    3
    
  2. Example 2

    Input
    1 2 3 5
    
    Expected output
    7