Problem G: 切煎饼

平面分割问题 可以看看我的另一题
https://blog.csdn.net/weixin_45485719/article/details/103220056

Description

王小二自夸刀工不错,有人放一张大的圆煎饼在砧板上,问他:饼不允许离开砧板,切100刀最多能切多少块?

Input

多组测试数据,每组输入1个整数,代表切的刀数

Output

每组输出1个整数,为最多能切的块数

Sample Input

1
2
3

Sample Output

2
4
7

代码实现

#include<iostream>
using namespace std;
long long f(int m)
{
    if(m==1)    return 2;
    else    return f(m-1)+m;
}
int main()
{
    int m;
    while(cin>>m)
        cout<<f(m)<<endl;
    return 0;
}
发布了149 篇原创文章 · 获赞 14 · 访问量 8997

猜你喜欢

转载自blog.csdn.net/weixin_45485719/article/details/103479085
今日推荐