Waterloo Cup-additive variable multiplication (two of which are not adjacent to the plus sign into the multiplication)

Source: Internet
Author: User

The subject requirements are as follows:


Additive variable multiplication

We all know: 1+2+3+. + 49 = 1225
Now you're asked to turn the two nonadjacent plus signs into multiplication, making the result 2015.

Like what:
1+2+3+...+10*11+12+...+27*28+29+...+49 = 2015
Is the answer that meets the requirements.

Please look for another possible answer,
and put the position of the front of the multiplication to the left of the number submitted (for example, is submitted 10).

Note: You are required to submit an integer, do not fill in any superfluous content.


Ideas:

1. Said the idea is actually no idea, according to the normal solution step-by-step procedures to write the OK.

2. Will 1+2+3+ + 49 of which two "+" into "*", with a double loop to traverse all possible results.

3. The outer loop of the variable I represents the previous "*", the inner loop of J represents the latter "*", followed by traversal.

4. Use variable TMP to save the result of changing the previous "+" in the program to "*". The code is TMP = RES = sum-(i+ (i-1)) +i* (i-1), which the reader needs to understand carefully.

5. Use the variable res to save the result of changing the latter "+" in the program to "*". The code is res = tmp-(j+ (j-1)) +j* (j-1).

6. Then the variable res determines whether the value is 2015. If yes, output I and the value for J. (the title only asks for the position of the previous "*", that is, the value of i).


The source code is as follows:

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.