蓝桥杯-加法变乘法

加法变乘法

我们都知道:1+2+3+ ... + 49 = 1225
现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015

比如:
1+2+3+...+10*11+12+...+27*28+29+...+49 = 2015
就是符合要求的答案。

请你寻找另外一个可能的答案,并把位置靠前的那个乘号左边的数字提交(对于示例,就是提交10)。

注意:需要你提交的是一个整数,不要填写任何多余的内容。

注意读清题,是其中两个。。。

代码:

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
typedef long long LL;
int main(){
    int ans=1225;
    for(int i=1;i<49;i++){
        for(int j=i+2;j<49;j++){
            ans=1225;
            ans-=(i+i+1);
            ans-=(j+j+1);
            ans+=i*(i+1);
            ans+=j*(j+1);
            if(ans==2015){
                printf("%d %d
",i,j);
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/handsomecui/p/5231283.html