L. 數數小木塊
Description
在墻角堆放著一堆完全相同的正方體小木塊,如下圖所示:

因為木塊堆得實在是太有規律了,你只要知道它的層數就可以計算所有木塊的數量了,
Input
只有一個整數 n ,表示這堆小木塊的層數,已知1 <= n <= 100 ,
Output
只有一個整數,表示這堆小木塊的總數量,
Sample Input
5
Sample Output
35
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,a,n=0;
cin>>a;
for(i=1;i<=a;i++)
{
for(j=a;j>=1;j--)
{
if(i+j-1==a)
{
n+=i*j;
}
}
}
cout<<n<<endl;
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/381943.html
標籤:其他
