Uva 913
梯形公式
(a+b)*h / 2
amount number
1 1
3 3 5 7 (1+3)*2 -1
5 9 11 13 15 17 (1+3+5)*2-1
...
(a+b)*h / 2
amount number
1 1
3 3 5 7 (1+3)*2 -1
5 9 11 13 15 17 (1+3+5)*2-1
...
- #include <iostream>
- using namespace std;
- int main()
- {
- long long int iSum, iNum;
- long long int iAmount, iHight; // (a+b)h/2
- int iLength, iCarry , iTemp;
- while ( cin >> iAmount )
- {
- iNum = 0;
- iHight = iAmount / 2 + 1;
- if ( iHight > 0 )
- {
- iSum = ( (1 + iAmount) * iHight - 3 );
- cout << iSum *3 << endl; // last three
- }
- else
- cout << 1 <<endl;
- }
- }
留言
張貼留言