This page is still under construction.

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

Hamming Sequence

Time limit1sMemory limit128 MB

Summary
Given three primes and an index i, find the i-th smallest number greater than 1 whose prime factors all lie among those three primes.
Level

Hard8 of 10

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

Problem

For three primes p1p_1, p2p_2, p3p_3, define the Hamming sequence H(p1,p2,p3)H(p_1, p_2, p_3).

H(p1,p2,p3)H(p_1, p_2, p_3) is the ascending list of natural numbers greater than 11 whose only prime factors are among p1p_1, p2p_2, p3p_3. (In particular, 11 is not included.)

For example, H(2,3,5)=2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,…H(2, 3, 5) = 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, \dots, and its fifth number is 66.

Input

The first line contains p1p_1, p2p_2, p3p_3, and ii. All four integers are less than 101810^{18}.

Output

Print the ii-th number of H(p1,p2,p3)H(p_1, p_2, p_3). The printed number is less than 101810^{18}.

Examples3

  1. Example 1

    Input
    7 13 19 100
    
    Expected output
    26590291
    
  2. Example 2

    Input
    2 3 5 5
    
    Expected output
    6
    
  3. Example 3

    Input
    2 3 5 1
    
    Expected output
    2