Odious Number in C++10 May 2025 | 4 min read In this article, we will discuss the Odious number in C++ with different approaches and examples. What is the Odious Number?If a number is positive and the number of set bits in its binary expansion is odd, the number is considered an Odious number. 1 is the first Odious number because it equals (0001) odd number of set bits. Any number that can be written in the powers of two (2^n) will be an Odious Number because those numbers will have 1 followed by zeroes in binary representation. Hence, 1 is an odd number it can be an Odious Number. The first ten Odious numbers are: 1, 2, 4, 7, 10, 11, 13, 14, 16, 19. For Example:Input:
Output:
Input:
Output:
Input:
Output:
Approach 1: Counting for several ones in binary representation.Let us take an example to check whether the given number is an Odious number or not: Output: ![]() Explanation:Function definition:
countOnes(int n):
IsOdious (int n):
Complexity Analysis:Time Complexity:
Space Complexity:
Approach 2: Using bitwise operations to count the set bits.Let us take another example to check whether the given number is an Odious number or not: Output: ![]() Explanation:Function Definition:
countOnesBitwise:
IsOdious Role:
Complexity Analysis:Time Complexity:
Space Complexity:
Next TopicAchilles-number-in-cpp |
Sign value of a polynomial in C++
The sign value of a polynomial is an important mathematical and computer science concept, especially in numerical methods, computational algebra, and algorithm design. In programming, especially with C++, it is very important to analyze and determine the sign of a polynomial at certain points or...
4 min read
Super-D Numbers in C++
Super-D numbers are distinct numbers whose sum matches the number itself when all of its digits are increased to a given power of D. For a number N, it satisfies the mathematical formula N=∑diD, where di are the digits of N. For instance, 153 is...
5 min read
Check if a given number is pronic in C++
In this article, we will discuss how to check if a given number is pronic in C++ with several examples. The product of two consecutive integers is called a pronic number, sometimes referred to as a rectangular number. Rectangular numbers (also called Pronic numbers) are numbers that...
4 min read
Cache-friendly code in C++
In this article, we will discuss cache-friendly code in C++ with its working and several examples. What is the ? Programming that maximizes memory access patterns to make the most of the CPU cache a quick, compact memory intended to hold frequently requested data is referred to as...
4 min read
Find All Good Indices in the Given Array in C++
Overview: In problem-solving and programming, effectively searching an array’s properties for certain indices is a recurring problem. Finding good indices in an array is one such problem. A good index generally fulfills a set of constraints like non-decreasing or non-increasing subarrays of a certain length around...
4 min read
Find the size of the largest '+' formed by all ones in a binary matrix in C++
The search for effective answers to a variety of problems in computer science and algorithmic problem-solving frequently brings us to fascinating riddles with combinatorial logic at their core. One such problem is figuring out how big the largest plus sign ('+') in a binary matrix that...
5 min read
std::strong_ordering in C++
In modern C++ (starting from C++20), a powerful and intuitive way to compare objects and values has been introduced through the concept of three-way comparison, often referred to as the spaceship operator (<=>). This operator allows you to compare two objects and get a single value...
8 min read
std::views::drop in C++
Introduction to C++ Ranges and Views New in C++20 are ranges and views to change how developers can work with containers. A range is another concept that defines a sequence of elements; algorithms can then work on them without having to iterate over them. Ranges increase the...
13 min read
Final NBA Match Pairing in C++
A string representing the final contest matches of n teams is returned. The teams are ranked from 1 to 𝑛, with Rank 1 being the best team and Rank n being the worst. The labels correspond to the teams' initial ranks. The matching procedure represents team...
4 min read
Find the Longest Turbulent Subarray in C++
Exploring the realm of challenges, the quest to find the subarray presents an intriguing puzzle. A turbulent subarray is identified by neighboring elements that alternate between increasing and decreasing order. Successfully tackling this task requires an understanding of array manipulation and pattern recognition. This article delves...
7 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India

