964A. Splits

题目地址:http://codeforces.com/problemset/problem/964/A

题目:

Let's define a split of nn as a nonincreasing sequence of positive integers, the sum of which is nn.

For example, the following sequences are splits of 88[4,4][4,4][3,3,2][3,3,2][2,2,1,1,1,1][2,2,1,1,1,1][5,2,1][5,2,1].

The following sequences aren't splits of 88[1,7][1,7][5,4][5,4][11,3][11,−3][1,1,4,1,1][1,1,4,1,1].

The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split [1,1,1,1,1][1,1,1,1,1] is 55, the weight of the split [5,5,3,3,3][5,5,3,3,3] is 22 and the weight of the split [9][9] equals 11.

For a given nn, find out the number of different weights of its splits.

Input

The first line contains one integer nn (1n1091≤n≤109).

Output

Output one integer — the answer to the problem.

Examples
input
Copy
7
output
Copy
4
input
Copy
8
output
Copy
5
input
Copy
9
output
Copy
5
Note

In the first sample, there are following possible weights of splits of 77:

Weight 1: [77]

Weight 2: [3333, 1]

Weight 3: [222222, 1]

Weight 7: [11111111111111]


题目大意:

比如7,它可以分成1个7,这时,序列中最多只有一个相同的数字。也可以是3,3,1,这时,序列中最多有两个相同的数字。求一共有几个最多相同数字不同的序列。

思路:一开始想着用set,先考虑只有1组成的序列,比如数字7/1=7,把7放入set。7/2=3,7-3=4,max(3,4),我们知道set内是不含相同的数字的,所以循环一遍后输出set的长度就好。但是超时了。

这说明,这题目比想象的更简单。还是拿7来打比方,先是可以分成1111111,把前两个1合成2,所以有211111,再31111,这样下来,只要求1的个数就好,那么每个数字最多也不过n/2+1个1.所以代码就很简单了。

代码:

#include<iostream>
using namespace std;
int main()
{
    long long int n;
    while(cin>>n)
    {
        cout<<n/2+1<<endl;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/zero_979/article/details/80055116

相关文章