2015 Blue Bridge Cup Group B c/c++ Question 6, Addition to Multiplication


We all know that addition becomes multiplication : 1+2+3+... + 49 = 1225
Now you are asked to turn two non-adjacent plus signs into multiplication signs, so that the result is 2015 For
example:
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 first multiplication sign (for the example, submit 10).

Idea: This question is very simple after finding the skills, but if you can't think of it, it may be very difficult to start. (Note that only two plus signs can be changed in the title)

         First of all, let's observe the difference between the equations from addition to multiplication. Assuming that the value before the first multiplication sign is i and the second is j, then the addition formula removes i, i+1 , j , j+1, and then Plus  i*(i+1)+j*(j+1) is the multiplication

Code:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=49;i++)
{
for(j=i+2;j<=49;j++)
{
if(1225-i-i-1+i*(i+1)-j-j-1+j*(j+1)==2015)
{
cout<<i<<" "<<j<<endl;
}
} } return 0; }


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325608811&siteId=291194637