# C++ code to count number of times stones can be given

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

Best Seller

66 Lectures 5.5 hours

Suppose we have a number n. Amal gives some stones to Bimal and he gives stones more than once, but in one move if Amal gives k stones, in the next move he cannot give k stones, so given stones in one move must be different than the previous move. We have to count the number of times Amal can give stones to Bimal.

So, if the input is like n = 4, then the output will be 3, because 1 stone then 2 stones then again 1 stones.

## Steps

To solve this, we will follow these steps −

return (n * 2 + 1) / 3

## 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) / 3;
}
int main(){
int n = 4;
cout << solve(n) << endl;
}

## Input

4

## Output

3
Updated on 30-Mar-2022 12:35:34