Arnab Chakraborty has Published 4293 Articles

Check if a number has two adjacent set bits in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 09:04:49

537 Views

Here we will see, if a number has adjacent set bits in its binary representation. Suppose the number 12 has two consecutive 1s (12 = 1100).To check this type of number, the idea is very simple. We will shift the number 1 bit, then do bitwise AND. If the bitwise ... Read More

Check if a number has same number of set and unset bits in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 09:00:47

264 Views

In this section we will check whether a number has same number of set bits and unset bits or not. Suppose the number 12 is there. Its binary representation is 1100. This has same number of 0s and 1s.The approach is simple. We will check each bit of the number, ... Read More

Check if a number can be written as sum of three consecutive integers in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 08:57:56

272 Views

In this section we will see, whether a number can be represented as tree consecutive numbers or not. Suppose a number is 27. This can be represented as 8 + 9 + 10.This can be solved in two different approach. The first approach is Naïve approach. In that approach, we ... Read More

Check if a number can be represented as a sum of 2 triangular numbers in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 08:39:47

178 Views

In this section, we will see if we can express one number as the sum of two triangular numbers or not. The triangular numbers are like below −From the example, we can see that 1, 3, 6, 10 are some triangular numbers. We need to express a number N (say ... Read More

Check if a number can be expressed as x^y (x raised to power y) in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 08:36:29

195 Views

Here we will check whether we can represent a number as power, like xy or not. Suppose a number 125 is present. This can be represented as 53. Another number 91 cannot be represented as power of some integer value.AlgorithmisRepresentPower(num): Begin    if num = 1, then return true    for i := 2, i2

Check if a number can be expressed as power in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 08:33:30

192 Views

Here we will check whether we can represent a number as power, like ab or not. Suppose a number 125 is present. This can be represented as 53. Another number 91 cannot be represented as power of some integer value.AlgorithmisRepresentPower(num): Begin    if num = 1, then return true    for i := 2, i2

Check if a number can be expressed as a^b in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 08:29:51

331 Views

Here we will check whether we can represent a number like ab or not. Suppose a number 125 is present. This can be represented as 53. Another number 91 cannot be represented as power of some integer value.AlgorithmisRepresentPower(num): Begin    if num = 1, then return true    for i := 2, i2

Check if a number can be expressed as a sum of consecutive numbers in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 08:26:52

510 Views

Here we will see if one number can be represented as sum of two or more consecutive numbers or not. Suppose a number is 12. This can be represented as 3+4+5.There is a direct and easiest method to solve this problem. If a number is power of 2, then it ... Read More

Check if a large number is divisible by 9 or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 08:18:34

304 Views

Here we will see how to check a number is divisible by 9 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 9, if the sum of digits is divisible by 9.Example Live Demo#include using namespace ... Read More

Check if a large number is divisible by 8 or not in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 27-Sep-2019 08:14:44

449 Views

Here we will see how to check a number is divisible by 8 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 8, if the number formed by last three digits are divisible by 8.Example Live Demo#include ... Read More

Advertisements