Server Side Programming Articles

Page 1201 of 2109

Count pairs (a, b) whose sum of cubes is N (a^3 + b^3 = N) in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 512 Views

We are given a number N. The goal is to find ordered pairs of positive numbers such that the sum of their cubes is N.We will do this by finding solutions to the equation a3 + b3 = N. Where a is not more than cube root of N and b can be calculated as cube root of (N-a3).Let’s understand with examples.Input N=35Output Count of pairs of (a, b) where a^3+b^3=N: 2Explanation Pairs will be (2, 3) and (3, 2). 23+33=8+27=35Input N=100Output Count of pairs of (a, b) where a^3+b^3=N: 0Explanation No such pairs possible.Approach used in the below program is as followsWe take integer N.Function ...

Read More

Count pairs (a, b) whose sum of squares is N (a^2 + b^2 = N) in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 411 Views

We are given a number N. The goal is to find ordered pairs of positive numbers such that the sum of their squares is N.We will do this by finding solutions to the equation a2+ b2 = N. Where a is not more than square root of N and b can be calculated as square root of (N-a2).Let’s understand with examples.Input N=100Output Count of pairs of (a, b) where a^3+b^3=N: 2Explanation Pairs will be (6, 8) and (8, 6). 62+82=36+64=100Input N=11Output Count of pairs of (a, b) where a^3+b^3=N: 0Explanation No such pairs possible.Approach used in the below program is as followsWe take integer N.Function squareSum(int ...

Read More

Count pairs (i,j) such that (i+j) is divisible by both A and B in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 297 Views

We are given variables N, M, A and B. The goal is to find ordered pairs of positive numbers( i, j ) such that their sum is divisible by both A and B. And 1

Read More

Count Primes in Ranges in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 8K+ Views

We are given range variables START and END. The goal is to find the count of prime numbers in the range [START, END].We will check if number i in range is prime by checking if any number other than 1 fully divides it and is between 1 and i/2. If it is prime. Increment count.Let’s understand with examples.Input Start=1 End=20Output Primes in Ranges : 8Explanation Primes between 1 and 20 are: 2, 3, 5, 7, 11, 13, 17, 19.Input Start=100 End=200Output Primes in Ranges : 21Explanation Primes between 100 and 200 are: 101 103 107 109 113 127 131 137 139 149 151 157 163 167 ...

Read More

Program to evaluate Postfix Notation in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 14K+ Views

Suppose we have postfix expression and we have to evaluate the value. Postfix expression is also known as Reverse polish notation. Here we have to use the stack data structure to solve the postfix expressions.So if the expression is “21+3*”, then the answer will be 9.Let us see the steps −for each character ch in the postfix expression, doif ch is an operator $\odot$ , thena := pop first element from stack, b := pop second element from the stackres := b $\odot$ apush res into the stackelse if ch is an operand, thenadd ch into the stackreturn element of ...

Read More

Count numbers whose sum with x is equal to XOR with x in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 257 Views

We are a number X. The goal is to find numbers between 0 and X whose sum with X is equal to XOR with X.We will do this by traversing no. from i=0 to i

Read More

Program to remove sublist to get same number of elements below and above k in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 219 Views

Suppose we have a list of numbers called nums and another number k, we can remove any sublist at most once from the list. We have to find the length of the longest resulting list such that the amount of numbers strictly less than k and strictly larger than k is the same.So, if the input is like nums = [6, 10, 8, 9, 3, 5], k = 6, then the output will be 5, as if we remove the sublist [9] then we will get [6, 10, 8, 3, 5] and there are two numbers [3, 5] which are ...

Read More

Count numbers whose XOR with N is equal to OR with N in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 179 Views

We are a number N. The goal is to find numbers between 0 and N whose OR with N is equal to XOR with N.We will do this by traversing no. from i=0 to i

Read More

Count number of ways to divide a number in parts in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 531 Views

We are given a positive number N. The goal is to count the number of ways in which the number N can be divided into 3 parts. The parts may or may not be equal. N lies in range [1, 5000].We will do this by using three for loops for 3 parts of the number. Check at the innermost loop that the sum of all three is equal to N. If true, then increment the count of ways.Let’s understand with examples.Input − N=5Output − Number of ways to divide N in 3 parts: 2Explanation − 5 can be shown as ...

Read More

Count numbers which can be represented as sum of same parity primes in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 262 Views

We are given an array Arr[] of positive integers of size N. The goal is to count the number of elements in that array which can be represented as sum of parity primes, that is they can be shown as a sum of the same prime number. Ex; 4= 2+2, 6=3+3 or 2+2+2The sum of any two odd or even prime numbers will always be even. And except 0 and 2 all even numbers can be represented as sum of same primes.Let’s understand with examples.Input Arr[] = { 2, 5, 10, 15, 20, 25 }Output Number which satisfy condition : 3Explanation Numbers as ...

Read More
Showing 12001–12010 of 21,090 articles
Advertisements