Sunidhi Bansal has Published 1100 Articles

Count Primes in Ranges in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:21:03

7K+ 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 ... Read More

Count strings that end with the given pattern in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:19:13

114 Views

We are given an array of strings str[] and a pattern string pat. The goal is to find the string elements of str[] that have pattern pat at the end.We will traverse each string of str and compare last characters with pat. If they match incrementLet’s understand with examples.Input str[]={ “kittens”, ... Read More

Count square and non-square numbers before n in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:17:02

725 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.Naive ApproachTraverse all numbers from 1 to N and check if it is a perfect square. If floor(sqrt(i))==ceil(sqrt(i)).Then the number is a perfect square.Efficient ApproachPerfect squares ... Read More

Count numbers which can be constructed using two numbers in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:14:58

172 Views

We are provided three numbers X, Y and N ( to define range [1, N] ). The goal is to find all the numbers in the range [1, N] that can be constructed using X and Y only any number of times..For example if X=2 and Y=3. Number 6 can ... Read More

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

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:13:20

209 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. ... 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 31-Oct-2020 05:11:27

134 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

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

Sunidhi Bansal

Sunidhi Bansal

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

241 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 ... 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 31-Oct-2020 05:07:58

275 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 ... Read More

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

Sunidhi Bansal

Sunidhi Bansal

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

77 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

Sunidhi Bansal

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

188 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

Advertisements