Copy and Submit II

题目链接
简单题
Description:

Input:
Input consists of several test cases. Each test case begins with an integer n. Then it’s followed by n integers a[i].

0

Output:
Maybe you can just copy and submit. Maybe not. 
这个地方有点Bug  (lll¬ω¬)

样例输入:

1
233
1
666

样例输出

234
667

题意:
就是给你一段代码,你可以选择直接提交,也可以选择不直接提交。内存限制才512k。

思路:
(lll¬ω¬) 直接提交肯定内存爆炸的。先看懂这段代码是干啥的,然后再优化。

其实也不难推,很轻易就可以发现,这段代码的作用。假设这个是三个数,n = 3,这三个数分别为,a,b,c.则这段代码的作用是求1+a+b+c+ab+ac+bc+abc。可以提取公因式 = (1+a)(1+b)(1+c);
这样以来就非常简单了。

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<set>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e3+5;
typedef long long ll;
const int MOD = 1000000007;
int n;
int main(){
    while(~scanf("%d",&n)){
        ll ans = 1;
        int temp;
        for(int i=0;i<n;i++){
            scanf("%d",&temp);
            ans = (ans*(1+temp)%MOD)%MOD;
        }
        cout<<ans<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值