#P9699. Matching Base Representations

    ID: 22846 Type: Default 1000ms 256MiB

Matching Base Representations

Matching Base Representations

Given four positive integers (x), (y), (A), and (B), find two positive integers (a) and (b) such that (2 \le a \le A), (2 \le b \le B), and [ f(x,a)=f(y,b), ] where for any positive integer (X) and base (b\ge2), [ f(X,b)={d_0,d_1,\dots,d_k}, \quad X=d_0+d_1\cdot b+\dots+d_k\cdot b^k, \quad 0\le d_i<b, ; d_k\ne0. ] If there are multiple solutions, you may output any one of them. If no solution exists, output -1 -1.

inputFormat

The input consists of a single line containing four positive integers (x), (y), (A), and (B), separated by spaces.

outputFormat

Output two integers (a) and (b) separated by a space, such that (2\le a\le A), (2\le b\le B), and (f(x,a)=f(y,b)). If no such pair exists, output -1 -1.

sample

6 6 10 10
2 2