Found 7197 Articles for C++

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

Sunidhi Bansal
Updated on 31-Oct-2020 05:09:48

350 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 (a, b) whose sum of cubes is N (a^3 + b^3 = N) in C++

Sunidhi Bansal
Updated on 31-Oct-2020 05:07:58

420 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 ordered pairs with product less than N in C++

Sunidhi Bansal
Updated on 31-Oct-2020 05:06:07

155 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

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

Sunidhi Bansal
Updated on 31-Oct-2020 05:04:21

278 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

Count of smaller or equal elements in the sorted array in C++

Ravi Ranjan
Updated on 10-Jun-2025 17:46:52

1K+ Views

In this article, we have a sorted array of integers. Our task is to find the count of elements of the given sorted array that are less than or equal to the given value K. Example Here are some examples of counting the array elements smaller than the given target element: Input: arr = {6, 12, 16, 23, 32, 45, 48, 50} target = 40 Output: 5 Input: arr = {6, 12, 15, 20, 32, 45, 48, 50} target = 20 Output: 4 Counting of smaller or equal elements in the sorted arrayHere is a list ... 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
Updated on 31-Oct-2020 04:59:30

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 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 of numbers from range[L, R] whose sum of digits is Y in C++

Sunidhi Bansal
Updated on 31-Oct-2020 04:57:09

304 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 of common multiples of two numbers in a range in C++

Sunidhi Bansal
Updated on 31-Oct-2020 04:55:08

2K+ Views

We are given two numbers A and B. Also provided two numbers START and END to define a range of numbers. The Ath tile has paint white and Bth tile has paint black. If the tile is painted both black and white then it turns grey. The goal is to find the total number of grey tiles .We will do this by traversing numbers from START to END and for each number we will check if the number is multiple of both A and B. If yes increment count.Let’s understand with examples.Input START=10 END=20 A=3 B=6Output Common multiples of A and B ... Read More

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

Sunidhi Bansal
Updated on 31-Oct-2020 04:53:26

614 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 numbers in range that are divisible by all of its non-zero digits in C++

Sunidhi Bansal
Updated on 31-Oct-2020 04:50:25

234 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] that are divisible by all of its non-zero digits . We will do this by traversing numbers from START to END and for each number we will check if the number is divisible by all non-zero digits using a while loop. If yes increment count.Let’s understand with examples.Input START=10 END=20Output Numbers that are divisible by all its non-zero digits: 14Explanation Numbers 10, 11, 12, 15, 20 are divisible by all their non-zero digits.Input START=100 END=200Output Numbers that are divisible ... Read More

Advertisements