

- 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 find xth element after removing numbers
Suppose we have two numbers n and x. First n natural numbers are written on a blackboard. In ith (i starts from 1) operation, we remove ith number from the blackboard. When there are less than i numbers, we stop removal task. We have to find x-th remaining number after stopping removal.
So, if the input is like n = 69; x = 6, then the output will be 12. In first operation, i = 1, so remove 1, then in second operation i = 2, but the sequence is 2, 3, 4 ... so second number is 3, remove 3, like this finally the xth number is 12.
Steps
To solve this, we will follow these steps −
return 2 * x
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; int solve(int n, int x){ return 2 * x; } int main(){ int n = 69; int x = 6; cout << solve(n, x) << endl; }
Input
69, 6
Output
12
- Related Questions & Answers
- K-th smallest element after removing some integers from natural numbers in C++
- C++ code to find minimal tiredness after meeting
- C++ code to find minimum stones after all operations
- C++ code to find tree height after n days
- Program to find string after removing consecutive duplicate characters in Python
- C++ code to find money after buying and selling shares
- C++ code to find corrected text after double vowel removal
- C++ code to find position of students after coding contest
- Program to find shortest string after removing different adjacent bits in Python
- Program to find mean of array after removing some elements in Python
- Maximize the maximum subarray sum after removing at most one element in C++
- C++ code to find final number after min max removal game
- C++ code to find composite numbers whose difference is n
- C++ code to find three numbers whose sum is n
- C++ code to count numbers after division elements greater than half of array size
Advertisements