ÀÂÒ
Language:

Remote Training on Programming

Problems On-line status Contests FAQ
For authors:
Register  ||  Login
 
Hello, Guest! Login or register.

414. Shortest Expression

Time Limit: 1 seconds
Memory Limit:64000KB
Points:10
View Problem Statistics Submit Problem added Undefined

A teacher of mathematics asks schoolboys to make up an arithmetic expression with value 
equal to N. It is possible to use natural numbers <= K, operations '+' and '*', 
and brackets. Petya want to make up an expression with minimal number of characters.
Write program to help Petya.

Input:
First line contains two natural numbers N (1<=N<=10000) - expression's value, 
and K (1<=K<=10000) - maximal number for using in expression.

Output:
Expression with minimal number of characters, written on a single line. 
If there are several solutions, write any of them.

Examples:
-------------------------------------------------------------------------
|STDIN  |                  STDOUT                  |explanation:        |
|       |                                          |length of expression|
-------------------------------------------------------------------------
|7 3    |3+1+3                                     |5                   |
-------------------------------------------------------------------------
|15 20  |15                                        |2                   |
-------------------------------------------------------------------------
|176 1  |(1+1+1+1)*(1+1+1+1)*(1+1+(1+1+1)*(1+1+1)) |41                  |
-------------------------------------------------------------------------

View Problem Statistics Submit Author/source:
Problems from Contests / VoSTU Selection Rounds / Selection Round on ACM ICPC 2007 /
411. Equal Sums 414. 412. Texture
We can all benefit by doing occasional "toy" programs, when artificial restrictions are set up, so that we are forced to push our abilities to the limit. The art of tackling miniproblems with all our energy will sharpen our talents for the real problems. Donald E. Knuth.
time generating 0.047 sec.
© Copyright VSTU, AVT, Nosov D.A.