此題把公式導出來就可以了,公式如下:
2 + (n-1)*(2 + 2 * (n - 1))/2;
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
while( cin >> n ) | |
{ | |
n = 2 + (n-1)*(2 + 2 * (n - 1))/2; | |
cout << n << endl; | |
} | |
return 0; | |
} |
沒有留言:
張貼留言