Description
一條直線可以把平面分成兩部分,兩條直線分成四部分。那么 n 條直線最多可以把平面分成幾部分?
Input
多組數據,每組數據一個正整數?1≤�≤1000。
Output
Sample
#0
Input
Copy
3 5
Output
Copy
7 16
Hint
小學奧數:要分的最多,就需要兩兩相交,且沒有任何三條直線交于一點。假設已有 n 條直線,在增加第 n+1 條時,與之前每條直線都有一個獨立交點, n 個交點把新的直線分成 n+1 段,每段都會把一個部分一分為二,所以增加了 n+1 塊。
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include "stdio.h"
#include <vector>
using namespace std;
// 1 2
// 2 4
// 3 7
// 4 11
// 5 16
int a[1005];
int main()
{int n;a[1] = 2;a[2] = 4;for (int i = 3; i <= 1005; i++){a[i] = a[i - 1] + i;}while (cin >> n){cout << a[n] << endl;}return 0;
}