It is often useful in mathematics to decide whether one integer is divisible by another. For example, if you multiply an integer by 7 (without using a calculator!) you may want to check quickly that you have performed the multiplication correctly by ensuring that the product is divisible by 7 (this does not guarantee that you were correct, but if it fails, you can be certain that your answer was incorrect.)
Most probably, you learned the rules for divisibility by 2, 3, 4, 5, 6, 9, and 10 in elementary school, and possibly 8 — but not 7! Most elementary school teachers will admit to not knowing the divisibility rule for 7, which is as follows:
- If the number has 1 or 2 digits, stop.
- Remove the last digit from the number and double it.
- Subtract the result from the rest of the number.
- Go back to step 1.
For example, let's say we want to check whether or not 13076 is divisible by 7. We remove the 6, double it to get 12, and then subtract 12 from 1307 to obtain 1295. We then remove the 5, double it to get 10, and subtract 10 from 129 to get 119. We then remove the 9, double it to give 18, and subtract 18 from 11 to obtain -7. Since this is divisible by 7, we can conclude that 13076 is divisible by 7.
Enter the proverbial PEG member who is brilliant at programming but
lousy at short questions. He (she?) is doing some Computer Number
Systems homework. However, using the computer to answer the question of
whether or not
Task
Given a base and a divisor, find a rule of the form "repeatedly remove
the last digit, multiply it by
Input
The first line of the input contains an integer
Output
For each test case, output a line containing either +
or -
followed by an integer +X
signifies that one is to remove the last digit, multiply it by -X
signifies that one is
to remove the last digit, multiply it by +X
in
preference to -X
.
Sample Input
2
10 7
6 5
Sample Output
-2
+1
Explanation
In the first test case, we are asked to find a base 10 divisibility rule
by 7. The answer, as already stated, is to remove the last digit, double
it, and subtract this from the rest of the number. In the second test
case, we are asked to find a base 6 divisibility rule by 5. The solution
is to remove the last digit and add it to the rest of the number, hence
Comments