Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 285 of 377

Find out the minimum number of coins required to pay total amount in C++

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

Suppose we have a number N, and unlimited number of coins worth 1, 10 and 25 currency coins. Find minimum number of coins we need to use to pay exactly amount N. Suppose N is 14, then number of coins will be 5, as one 10 value coin and four 1 value coin.To solve this, we have to use these steps −If N < 10, then return N number of 1 value coinsIf N > 9 and N < 25, then divide the value with 10, and get the result, the remaining will be covered using 1 value coin, add ...

Read More

Find Harmonic mean using Arithmetic mean and Geometric mean using C++.

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

Here we will see how to get the Harmonic mean using the arithmetic mean and the geometric mean. The formula for these three means are like below −Arithmetic Mean − (a + b)/2Geometric Mean − $$\sqrt{\lgroup a*b\rgroup}$$Harmonic Mean − 2ab/(a+b)The Harmonic Mean can be expressed using arithmetic mean and geometric mean using this formula −$$HM=\frac{GM^{2}}{AM}$$Example#include #include using namespace std; double getHarmonicMean(int a, int b) {    double AM, GM, HM;    AM = (a + b) / 2;    GM = sqrt(a * b);    HM = (GM * GM) / AM;    return HM; } int main() ...

Read More

Find if a number is part of AP whose first element and difference are given using C++.

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

Suppose we have the first element of AP, and the differenced. We have to check whether the given number n is a part of AP or not. If the first term is a = 1, differenced = 3, and the term x = 7 will be checked. The answer is yes.To solve this problem, we will follow these steps −If d is 0, and a = x, then return true, otherwise false.Otherwise, if d is not 0, then if x belongs to the sequence x = a + n * d, where n is a non-negative integer, only if (n ...

Read More

Find if two rectangles overlap using C++.

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

We know that a rectangle can be represented using two coordinates, the top left corner, and the bottom right corner. Suppose there are two rectangles, we have to check whether these two overlap or not. There are four coordinate points (l1, r1) and (l2, r2).l1 is the top-left corner of first rectangler1 is the bottom-right corner of the first rectanglel2 is the top-left corner of second rectangler2 is the bottom-right corner of the second rectangleWe have assumed that the rectangles are parallel to the coordinate axes. To solve this, we have to check a few conditions.One rectangle is above the ...

Read More

Find the multiple of x which is closest to a^b in C++

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

Suppose we have three integers, a, b and x. The task is to get the multiple of x, which is closest to ab. So if a = 5, b = 4 and x = 3, then output will be 624. As 54 = 625, and 624 is the multiple of 3, which is closest to 625.The task is simple. we have to follow these steps to solve this problem −calculate num := abThen find f := floor of (num/x)Now the closest element at the left will be cl = x * f, and at right will be cr = x ...

Read More

Find permutation of first N natural numbers that satisfies the given condition in C++

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

Suppose we have two integers N and K, and we have to find the permutation P of first N natural numbers such that there are exactly K elements which satisfies the condition GCD(P[i], i) > 1 for all 1

Read More

Find largest prime factor of a number using C++.

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

Consider we have an element x, we have to find the largest prime factor of x. If the value of x is 6,  then-largest prime factor is 3. To solve this problem, we will just factorize the number by dividing it with the divisor of a number and keep track of the maximum prime factor.Example#include #include using namespace std; long long getMaxPrimefactor(long long n) {    long long maxPF = -1;    while (n % 2 == 0) {       maxPF = 2;       n /= 2;    }    for (int i = 3; i 2)    maxPF = n;    return maxPF; } int main() {    long long n = 162378;    cout

Read More

Find permutation of n which is divisible by 3 but not divisible by 6 in C++

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

Suppose we have a number n, and we have to find the permutation of this number, that is divisible by 3, but not divisible by 6. If no such value can be made, then return -1. For example, if n is 336, then the output can be 363.As we know a number is divisible by 6 means it is divisible by 3 and 2. So each even number that is divisible by 3, will be divisible by 6. If we interchange the digits of a number which is divisible by 3 and also even, to make it odd, it will ...

Read More

Find prime number K in an array such that (A[i] % K) is maximum in C++

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

Suppose we have an array A with n integers. We have to find one element K such that K is prime, and A[i] mod K is maximum for all valid i among all possible values of K. If no such numbers are found, then return -1. For example, if A = [2, 10, 15, 7, 6, 8, 13], then the output will be 13. There are three prime numbers 2, 7, and 13. The maximum possible values of A[i] mod 2 is 1, (15 mod 2), for 7, it will be 6 mod 7 = 6, and for 13, it ...

Read More

Find product of prime numbers between 1 to n in C++

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

Suppose we have a number n. We have to find the product of prime numbers between 1 to n. So if n = 7, then output will be 210, as 2 * 3 * 5 * 7 = 210.We will use the Sieve of Eratosthenes method to find all primes. Then calculate the product of them.Example#include using namespace std; long PrimeProds(int n) {    bool prime[n + 1];    for(int i = 0; i

Read More
Showing 2841–2850 of 3,768 articles
« Prev 1 283 284 285 286 287 377 Next »
Advertisements