Arithmetic and Geometric Sequences

Count integers from 1 to u that lie in an arithmetic sequence or a geometric sequence, counting overlaps only once.

Medium5MathHash mapImplementationBrute forceNo attempts yetTime limit2sMemory limit512 MB

Problem

The arithmetic sequence AA has general term a+b×xa + b \times x and the geometric sequence GG has general term c×dyc \times d^y, where xx and yy are non-negative integers.

Given aa, bb, cc, dd, and uu, write a program that counts the integers from 11 to uu that belong to AA or to GG. A number that belongs to both sequences is counted as well. If the same number appears several times in a sequence, it still counts once.

Input

The first line contains aa, bb, cc, dd, and uu, separated by spaces. (1a,b,c,u10121 \le a, b, c, u \le 10^{12}, 1d1051 \le d \le 10^5)

Output

Print on the first line how many integers between 11 and uu inclusive belong to the arithmetic sequence AA or to the geometric sequence GG.

Note

For a=452a = 452, b=24b = 24, c=4c = 4, d=5d = 5, and u=600u = 600, the numbers that satisfy the condition are 44, 2020, 100100, 452452, 476476, 500500, 524524, 548548, 572572, 596596.