问题2680--Toothpick Arithmetic

2680: Toothpick Arithmetic

[命题人 : ]
时间限制 : 3.000 sec  内存限制 : 64 MB

题目描述

A toothpick expression uses toothpicks to represent a positive integer. The expression consists of operands and operators. Each operand consists of one or more vertical toothpicks ("|"); the value of the operand is the number of toothpicks. The operators that can appear in an expression are addition and multiplication. The addition operator is the plus sign ("+"), which consists of one vertical and one horizontal toothpick. The multiplication operator is the letter "x", which also consists of two toothpicks. Multiplication has precedence over addition. The expression must begin with an operand. Thereafter, operators and operands alternate. Finally, the expression must end with an operand. Given a positive integer, your program must represent it as a toothpick expression, using the smallest number of toothpicks.

输入

The input file will consist of one or more lines; each line will contain data for one instance of the problem. More specifically, each line will contain one positive integer, not exceeding 5000.

输出

Each line of input will give rise to one line of output, consisting of: the number of toothpicks used in the expression, and the given integer from the input, formatted as shown in the sample output. The word "toothpicks" (even if the answer is 1) will be preceded by one blank space and followed by a colon and one blank space.

样例输入 Copy

35
37
53

样例输出 Copy

14 toothpicks: 35
17 toothpicks: 37
21 toothpicks: 53

来源/分类