Description
王小二自誇刀工不錯,有人放一張大的圓煎餅在砧板上,問他:餅不允許離開砧板,切100刀最多能切多少塊?
Input
多組測試數據,每組輸入1個整數,代表切的刀數
Output
每組輸出1個整數,為最多能切的塊數
Sample Input
1 2 3
Sample Output
2 4 7
#include<stdio.h> int f(int n) { if(n==1) return 2; else return n+f(n-1); } int main() { int n; while(scanf("%d",&n)!=EOF) { printf("%d\n",f(n)); } return 0; }
刀數 最多切的塊數
0 1=1
1 1+1=2
2 1+1+2=4
3 1+1+2+3=7
4 1+1+2+3+4=11
5 1+1+2+3+4+5=16
. .....
n 1+1+2+3+4+5+...+n=1+(1+n)*n/2
