我们都知道:1+2+3+ ... + 49 = 1225
现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015
比如:
1+2+3+...+10*11+12+...+27*28+29+...+49= 2015
就是符合要求的答案。
请你寻找另外一个可能的答案,并把位置靠前的那个乘号左边的数字提交(对于示例,就是提交10)。
注意:需要你提交的是一个整数,不要填写任何多余的内容。
思路:
水题,两个for循环遍历查找
答案:16
代码:
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<cmath> #include<algorithm> #include<string> #include<string.h> #include<set> #include<queue> #include<stack> #include<functional> using namespace std; int main() { int sum = 0; for (int i = 1; i <= 49; i++) { sum += i; } int ans = sum; //cout << ans << endl; for (int i = 1; i <= 47; i++) { for (int j = i + 2; j <= 48; j++) { ans = ans - i - i - j - j - 2; ans = ans + i*(i + 1) + j*(j + 1); if (ans == 2015)cout << i << endl; ans = sum; } } system("pause"); return 0; }