TopcoderArchiveVisit Topcoder
SRM1 Apr 2002
SRM 76

Ones

Problem statement, definition, constraints, and public examples.

Problem Statement

PROBLEM STATEMENT:
At your disposal are: the numeral one, addition, multiplication, and the
parentheses.  Express a given number with the fewest amount of ones possible.

DEFINITION:
Class Name:  Ones
Method Name: express
Parameters:  int
Return:	     int
Method signature: (make sure your method is public) int express(int n)

INPUTS:
n is an integer between 1 and 10000 inclusive

EXAMPLES
3   returns 3   (1+1+1)
7   returns 6   (1+1+1)*(1+1)+1
46  returns 12  (1+1+1)*(1+1+1)*(1+1+1+1+1)+1
1983 returns 23 (1+1+1)*(((1+1)*(1+1+1)*(1+1+1)*(1+1+1)+1)*(1+1+1)*(1+1+1+1)+1)

FURTHER EXAMPLES
94    returns 15
167   returns 17
661   returns 20
10000 returns 28

Definition

Class:
Ones
Method:
express
Parameters:
int
Returns:
int
Method signature:
int express(int param0)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems