C++ Articles

Page 73 of 597

Count ordered pairs of positive numbers such that their sum is S and XOR is K in C++

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

We are given two numbers S and K. The goal is to find ordered pairs of positive numbers such that their sum is S and XOR is K.We will do this by starting from i=1 to i

Read More

Count numbers with difference between number and its digit sum greater than specific value in C++

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

We are provided two numbers N which defines a range [1, N] and D which is a difference.The goal is to find all the numbers in the range [1, N] such that the [ number - (sum of its digits) ] > D. We will do this by traversing numbers from 1 to N and for each number we will calculate its digit sum using a while loop. Check if the number and calculated digit sum has a difference more than D.Let’s understand with examples.Input N=15 D=5Output Numbers such that difference b/w no. and its digit sum greater than value D: 6Explanation Numbers ...

Read More

Count ordered pairs with product less than N in C++

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

We are given a number N. The goal is to find ordered pairs of positive numbers such that their product is less than N.We will do this by starting from i=1 to i

Read More

Count of numbers from range[L, R] whose sum of digits is Y in C++

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

We are provided two numbers START and END to define a range of numbers.The goal is to find all the numbers in the range [START, END] which have sum of digits equal to a given number Y.We will do this by traversing numbers from START to END and for each number we will count the sum of its digit using a while loop. If this sum is equal to Y, increment count.Let’s understand with examples.Input START=10 END=20 Y=4Output Numbers such that digit sum is equal to Y: 1Explanation Number 13 has digit sum equal to 4.Input START=10 END=50 Y=5Output Numbers such that digit sum is ...

Read More

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 of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M in C++

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

We are provided two numbers START and END to define a range of numbers.The goal is to find all the numbers in the range [START, END] which have no digit as 0 and have sum of digits equal to a given number N. Also the numbers are divisible by MWe will do this by traversing numbers from START to END and for each number we will count the sum of its digit using a while loop ( only if all digits are non zero ). If this sum is equal to N and the number is divisible by M, increment ...

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

Count pairs from two arrays having sum equal to K in C++

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

We are given two arrays Arr1[] and Arr2[] and a number K. The goal is to find unique pairs of elements of both arrays such that their sum is K. Pairs will be of form ( Arr1[i], Arr2[j] ) where Arr1[i]+Arr2[j]==K.We will traverse using two loops for i and j. If sum (Arr1[i]+Arr2[j])==K. And the pair doesn’t exist in unordered_map. Add it to the map and increment count.Let’s understand with examples.Input Arr1[]={ 1, 3, 2, 4, 3, 2 }; Arr2[]={ 0, 2, 1, 2, 3 }; K=4Output Number of pairs with sum K : 4Explanation Pairs will be ( Arr1[0], Arr2[4] ) → ...

Read More
Showing 721–730 of 5,962 articles
« Prev 1 71 72 73 74 75 597 Next »
Advertisements