Time limit for poetry-like stones: 5000 MS | memory limit: 65536 KB
-
Description
-
In front of you
There are many
Gravel
After you
Careful check
You confirm
The number of stones is N.
You can
Set this
N gravel stones
Divided
Several heaps
When you
Divide the stones
You will
Get a score
Its value
The product of the quantity of each pile of gravel
Therefore
You are thinking
How can we
So that the score is greater?
-
Input
-
The input includes multiple groups of test data. Each group of test data has only one positive integer N (1 <=n <= 5000)
The last line of the input data is an integer of 0, indicating that the input is complete and no processing is required.
-
Output
-
For each group of test data, an integer is output to give the given n stones the highest score.
-
Sample Input
-
24100
-
Sample output
-
2436
-
Prompt
-
A. Two stones are divided into one pile, four stones are divided into one pile or two piles (two in each pile), and 10 stones are divided into three piles (4 + 3 + 3)
B. The number of answers may be huge. We guarantee that the number of answers is within 800 digits.
A simple decomposition problem. Considering the large data size, it is more convenient to use Java.
Import Java. math. biginteger; import Java. util. role; public class main {public static void main (string [] ARGs) {role in = new role (system. in); int N; biginteger M = biginteger. zero; n = in. nextint (); While (n! = 0) {If (n = 1) M = biginteger. one; else if (n = 2) M = biginteger. valueof (2); else if (N % 3 = 0) {M = biginteger. valueof (3 ). pow (N/3);} else if (N % 3 = 1) {M = biginteger. valueof (3 ). pow (N/3-1 ). multiply (biginteger. valueof (4);} else if (N % 3 = 2) {M = biginteger. valueof (3 ). pow (N/3 ). multiply (biginteger. valueof (2);} system. out. println (M. tostring (); n = in. nextint ();}}}