Little Johnny likes to draw a lot. A few days ago he painted lots of straight lines on his sheet of paper. Then he counted in how many zones the sheet of paper was split by these lines. He noticed that this number is not always the same. For instance, if he draws
2 lines, the sheet of paper could be split into
4,
3 or even
2 (if the lines are identical) zones. Since he is a very curious kid, he would like to know which is the maximum number of zones into which he can split the sheet of paper, if he draws
N lines. The sheet of paper is to be considered a very large (=infinite) rectangle.
Input
The input file will contain an integer number: N (0<=N<=65535).
Output
You should output one integer: the maximum number of zones into which the sheet of paper can be split if Johnny draws N lines.
Sample Input #1
0
Sample Output #1
1
Sample Input #2
1
Sample Output #2
2
切饼问题变形。 公式:f(n)=n*(n+1)/2
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include<vector>
#include<map>
#include<deque>
#include<list>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
long long w=(long long)n*(n+1)/2+1;
printf("%lld\n",w);
return 0;
}
王小二切饼(http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2050)
题目描述
王小二自夸刀工不错,有人放一张大的煎饼在砧板上,问他:“饼不许离开砧板,切n(1<=n<=100)刀最多能分成多少块?”
输入
输入切的刀数n。
输出
输出为切n刀最多切的饼的块数。
示例输入
100
示例输出
5051
代码一样。