Copy and Submit II

 

 

 The memory of this question is only 512k. It must be wrong if you submit it directly, so you need to optimize it. First of all, you must understand what the code is doing.

For example, if you input 3 numbers a, b, c, you should output 1+a+b+c+ab+ac+bc+abc, when I did it, I pushed it to this step, and then I don't know how to do it. , I came back and asked about it before I found out that there is a formula

1+a+b+c+ab+ac+bc+abc=(1+a)(1+b)(1+c)

This is easy to do, my code is as follows:

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 const int M = 1000000007;
 6 
 7 int main()
 8 {
 9     int n,temp;
10     long long ans;
11     while (scanf("%d", &n)!=EOF)
12     {
13         ans = 1;
14         for (int i = 0; i < n; i++)
15         {
16             scanf("%d", &temp);
17             ans = (ans*(1 + temp) % M) % M;
18         }
19         printf("%ld\n", ans);
20     }
21     return 0;
22 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324758536&siteId=291194637
ii
Recommended