1011 stones with the same poems

Source: Internet
Author: User
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 ();}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.