LCC/Moose '20 Contest 5 J3 - Ping Difference

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Bob is playing his favourite game, Balorant.

He is not having a good time because he keeps losing. Of course, Bob thinks that he is the better player so the problem must be his connection speed to the server, otherwise known as ping.

In Globgalob City, where Bob lives, ping works a bit differently. For data to be received, a signal is sent out from the router at location X to the server at location Y, where X and Y are both integers. The data travels in steps in either the positive or negative direction. The distance the data travels at step i follows the sequence K^P, K^{P-1}, ... , K^1, K^0. The value of K is the frequency, which is dependant on the router. The value of P is an arbitrary exponent that is determined by the router such that the data will make it to the server while minimizing its value. The ping is the number of steps the data must take before it reaches the server. For this problem, it is guaranteed that the data can be received by the server.

Bob has hacked into his opponent's router and has figured out its location and frequency. He wants you to determine what his and his opponent's pings are. Can you help him?

Input Specification

The first line contains a single integer, the location of the server Y (1 \le Y \le 10^9)

The second line contains two integers, the location of Bob's router followed by his router's frequency, A, B (1 \le A \le 10^9, 2 \le B \le 8)

The third line contains two integers, the location of the opponent's router followed by their router's frequency, C, D (1 \le C \le 10^9, 2 \le D \le 8)

Output Specification

Output two space-separated integers, Bob's ping and his opponent's ping.

Sample Input

15
195 6
11 2

Sample Output

2 1

Sample Explanation

Bob's data goes from 195 to 15 as follows 195 - 6^3 + 6^2 = 15. Note, that since the data arrived to the server in two pings, it stops travelling.

His opponent's data goes from 12 to 15 as follows 11 + 2^2 = 15


Comments

There are no comments at the moment.