Blue Bridge Cup-addition variable multiplication (Java)

Source: Internet
Author: User

Blue Bridge Cup sixth provincial race topic-addition variable multiplication (Java)

Topic:

we all know: 1+2+3+ ... + $ = 1225

you are now asked to turn two of these nonadjacent plus signs into multiplication sign, making the result -

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 submit the number to the left of the front multiplication sign (for example, commit Ten ).

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

My train of thought : Example: 1+2+3+...+10*11+12+...+27*28+29+...+49 =

We split 10*11 = 10+10*10 27*28 = 27+27*27

Translate to: 1+2+3+...+9+10+10*10+ 12+...+26+27+ 27*27+29+...+49 =

Both sides plus 11+28

1+2+3+...+9+10+10*10+11+ 12+...+26+27+ 27*27+28+29+...+49 = 2015+11+28

convert to:   1225+ 10*10+27*27 = 2015+11+28= 2017+10+27

According to this idea: using two-layer cyclic i,j to represent the position of multiplication sign respectively to obtain the judging conditions

1225+ i*i + j*j = = 2017+i+j

 Public class Demo6 {    publicstaticvoid  main (string[] args) {        for ( int i = 1; I < 49;  i++) { for (int j = i + 2; j <; J + +)                {if (1225 + i * i + J * j = + i + j) {                    System.out.println (i);     }}}}

Execution Result: 10 16

Answer: 16

Blue Bridge Cup-addition variable multiplication (Java)

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.