Programming Articles - Page 2406 of 3363

Python Program to Print Numbers in an Interval

Pavitra
Updated on 27-Sep-2019 11:06:50

540 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven the starting and ending range of an interval. We need to print all the numbers in the interval given.A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.There are two for loops, first for loop is for getting the numbers in the interval and second loop for the checking whether the number is prime or not.Now let’s see the implementation.Example Live Demostart = 10 end = 29 for val in range(start, end + ... Read More

How to deserialize a JSON to Java object using the flexjson in Java?

Aishwarya Naglot
Updated on 12-May-2025 14:28:18

5K+ Views

Deserializing a JSON to a Java object means converting a JSON string into a Java object.The deserialize() Method of the Flexjson Library We will be using the Flexjson library to deserialize a JSON to a Java object in Java. The Flexjson library is a lightweight library that is used for serializing as well as deserializing Java objects to and from JSON. A JSONDeserializer is the main class for performing deserialization of JSON to Java objects. We can deserialize a JSON string to a Java object using the deserialize(String json, Class type) method of JSONDeserializer. Syntax of deserialize() Method The syntax of the ... Read More

Check if a number N starts with 1 in b-base in C++

Arnab Chakraborty
Updated on 27-Sep-2019 10:49:33

220 Views

We have a number N and a base b. In this program we have to check whether the number is starting with 1 in base b or not. Suppose a number 6 is given. In binary this is 110, so it starts with 1, in base 4 also it will be 124. Here also it starts with 1.As we know, if a number N is represented in base b, b gets converted to m+1 bit sequence bm bm-1 … b0. This implies bm bm + bm-1 * bm-1 + … + b0*b0 = N. The largest number will be 2*bm ... Read More

Check if a number is Quartan Prime or not in C++

Akansha Kumari
Updated on 23-Jul-2025 18:48:18

421 Views

The Quartan primes are prime numbers that can be represented as x^4 + y^4. Where x, y > 0. Some Quartan prime numbers are {2, 17, 97, …}.In this article, we will learn how to check whether a number is Quartan Prime or not in C++. Consider the following input and output scenarios to understand the concept better: Scenario 1 Input: 17 Output: The number is Quartan Prime Explanation Here, we can represent the given number in the form of x^4 + y^4; (1)^4 + (2)^4 => 1 + 16 = 17. Scenario 2 Input: 12 Output: The number ... Read More

Check if a number is Full Prime in C++

Arnab Chakraborty
Updated on 27-Sep-2019 10:37:39

376 Views

Here we will see, how to check, whether a number is full prime or not. A number is said to be a full prime, if it is prime, and all of its digits are also prime. Suppose a number is 37, this is full prime. But 97 is not full prime as 9 is not a prime number.One efficient approach is that; first we have to check whether any digit is present that is not prime. Digits must be in 0 to 9. In that range 2, 3, 5 and 7 are prime, others are not prime. If all are ... Read More

Check if a number is a Pythagorean Prime or not in C++

Akansha Kumari
Updated on 24-Jul-2025 18:17:32

1K+ Views

The Pythagorean primes are prime numbers that can be represented in the form 4n + 1, where n is a non-negative integer. These primes have a special property as they can be expressed as the sum of two square numbers. In other words, a prime number p is called a Pythagorean prime if: p is prime, and p ≡ 1 (mod 4), i.e., when divided by 4, it leaves a remainder of 1. For example: 5 = 4x1 + 1 = 22 + ... Read More

Check if a number is a power of another number in C++

Arnab Chakraborty
Updated on 27-Sep-2019 09:13:37

635 Views

Here we will see, whether a number is power of another number or not. Suppose a number 125, and another number 5 is given. So it will return true when it finds that 125 is power of 5. In this case it is true. 125 = 53.AlgorithmisRepresentPower(x, y): Begin    if x = 1, then       if y = 1, return true, otherwise false    pow := 1    while pow < y, do       pow := pow * x    done    if pow = y, then       return true    return false ... Read More

Check if a number is a Mystery Numbers in C++

Arnab Chakraborty
Updated on 27-Sep-2019 09:07:29

771 Views

Here we will see how to check whether a number is Mystery number or not. A Mystery number is a number that can be represented by sum of two numbers, and the numbers re reverse of each other. Let us see the code to get better idea. We have to check all pairs and find the decision.Example Live Demo#include using namespace std; int revNum(int str) {    string s = to_string(str);    reverse(s.begin(), s.end());    stringstream ss(s);    int rev = 0;    ss >> rev;    return rev; } bool isMysteryNumber(int n) {    for (int i=1; i

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

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

557 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 AND result is non-zero, then there must be some consecutive 1s.Example Live Demo#include using namespace std; bool hasConsecutiveOnes(int n) {    if((n & (n >> 1)) == 1){    return true;    }else{       return false;    } } int main() {    int num = 67; //1000011    if(hasConsecutiveOnes(num)){       cout

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

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

290 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, and if that is 1, then increase set_bit_count, and if it is 0, then increase unset_bit_count. Finally, if they are same, then return true, otherwise false.Example Live Demo#include using namespace std; bool hasSameSetUnset(int n) {    int set_count = 0, unset_count = 0;    while(n){       if((n & ... Read More

Advertisements