Number of briquettes in the 7th Blue Bridge Cup A in 2016


Number of briquettes

There is a pile of briquettes, which form a triangular pyramid. In particular:
The first put a layer,
the second layer 3 (arranged in a triangle),
the third layer 6 (arranged in a triangle),
the fourth layer 10 (arranged in a triangle),
....
If a total of 100 Layer, how many briquettes are there?

Please fill in the number indicating the total number of briquettes.
Note: Your submission should be an integer, do not fill in any extra content or explanatory text.

1 #include <bits / stdc ++. H> 
 2  using  namespace std;
 3  int main () {
 4      int n = 0 ; // Number of briquettes in this layer 
5      int sum = 0 ; // Cumulative briquettes 
6      for ( int i = 0 ; i <= 100 ; i ++ ) {
 7          n + = i;
 8          sum + = n;
 9      }
 10      cout << sum;
 11 }

Answer 171700

100 can be changed to other numbers to verify

 

Guess you like

Origin www.cnblogs.com/taiga/p/12677109.html