Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
Statistical Charts
Submit Problem
Online Status
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Time Limit: 3000MSMemory Limit: 65536K
Total Submissions: 3556Accepted: 711


Coco is a clever boy, who is good at mathematics. However, he is puzzled by a difficult mathematics problem. The problem is: Given three integers N, K and M, N may adds ('+') M, subtract ('-') M, multiples ('*') M or modulus ('%') M (The definition of '%' is given below), and the result will be restored in N. Continue the process above, can you make a situation that "[(the initial value of N) + 1] % K" is equal to "(the current value of N) % K"? If you can, find the minimum steps and what you should do in each step. Please help poor Coco to solve this problem.

You should know that if a = b * q + r (q > 0 and 0 <= r < q), then we have a % q = r.


There are multiple cases. Each case contains three integers N, K and M (-1000 <= N <= 1000, 1 < K <= 1000, 0 < M <= 1000) in a single line.

The input is terminated with three 0s. This test case is not to be processed.


For each case, if there is no solution, just print 0. Otherwise, on the first line of the output print the minimum number of steps to make "[(the initial value of N) + 1] % K" is equal to "(the final value of N) % K". The second line print the operations to do in each step, which consist of '+', '-', '*' and '%'. If there are more than one solution, print the minimum one. (Here we define '+' < '-' < '*' < '%'. And if A = a1a2...ak and B = b1b2...bk are both solutions, we say A < B, if and only if there exists a P such that for i = 1, ..., P-1, ai = bi, and for i = P, ai < bi)

Sample Input

2 2 2
-1 12 10
0 0 0

Sample Output



PKU Monthly,Wang Yijie

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator