- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ code to count number of weight splits of a number n

Suppose we have a number n. We can split n as a nonincreasing sequence of positive integers, whose sum is n. The weight of a split is the number of elements in the split that are equal to the first element. So, the weight of the split [1,1,1,1,1] is 5, the weight of the split [5,5,3,3,3] is 2 and the weight of the split [9] equals 1. We have to find out the number of different weights of n's splits.

So, if the input is like n = 7, then the output will be 4, because possible weights are [7], [3, 3, 1], [2, 2, 2, 1], [1, 1, 1, 1, 1, 1, 1]

## Steps

To solve this, we will follow these steps −

return (n / 2 + 1)

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; int solve(int n){ return (n / 2 + 1); } int main(){ int n = 7; cout << solve(n) << endl; }

## Input

7

## Output

4

- Related Questions & Answers
- C++ code to count number of notebooks to make n origamis
- C++ code to count number of unread chapters
- C++ code to count number of even substrings of numeric string
- Count number of factors of a number - JavaScript
- C++ code to count number of packs of sheets to be bought
- Program to count the number of ways to distribute n number of candies in k number of bags in Python
- Write a program in Python to count the number of digits in a given number N
- C++ code to count number of times stones can be given
- C++ code to count number of lucky numbers with k digits
- Count number of paths whose weight is exactly X and has at-least one edge of weight M in C++
- C++ program to count minimum number of operations needed to make number n to 1
- Program to count number of stepping numbers of n digits in python
- C++ code to count number of operations to make two arrays same
- C++ code to count number of dice rolls to get target x
- Count total number of digits from 1 to N in C++

Advertisements