Given an array arr[] of N positive integers, the task is to find the minimum number of operations required to make the GCD of array element odd such that in each operation an array element can be divided by 2.Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the […]

Continue ReadingGiven a 2D array arr[][] consisting of N*N positive integers, the task is to generate an N-length array such that Greatest Common Divisors(GCD) of all possible pairs of that array is present in the array arr[][].Examples:Input: N = 4, arr[] = {2, 1, 2, 3, 4, 3, 2, 6, 1, 1, 2, 2, 1, 2, […]

Continue ReadingGiven an array arr[] consisting of N integers, the task for every ith element of the array is to find the number of non co-prime pairs from the range [1, arr[i]].Examples:Input: N = 2, arr[] = {3, 4}Output: 2 4Explanation:All non-co-prime pairs from the range [1, 3] are (2, 2) and (3, 3).All non-co-prime pairs from […]

Continue ReadingMinimum possible value of D which when added to or subtracted from K repeatedly obtains every array elementGiven an array arr[] of size N and an integer K, the task is to find the maximum possible value of D, such that every array element can be obtained, starting from the initial value of K, by […]

Continue ReadingPrint all numbers that are divisors of N and are co-prime with the quotient of their divisionGiven a positive integer N, the task is to print all the numbers, say K, such that K is a divisor of N and K and N / K are coprime.Examples:Input: N = 12 Output: 1 3 4 12 […]

Continue ReadingSort an array in increasing order of GCD of their digitsGiven an array arr[] consisting of N positive integers, the task is to sort the array arr[] according to the increasing order of GCD of digits of each element. If GCD of two or more elements are the same then, sort according to their values.Examples:Input: […]

Continue Readingimport java.io.*;import java.lang.*;import java.util.*;class GFG{static int gcd(int a, int b){ if (a == 0) return b; return gcd(b % a, a);}static void update(int arr[], int n){ for(int i = 0; i < n; i++) { int d = 0; int coPrime = -1; for(int j = 2; j

Continue ReadingCount numbers up to C that can be reduced to 0 by adding or subtracting A or B Given three non-negative integers A, B, and C, the task is to count the numbers in the range [1, C] that can be reduced to 0 by adding or subtracting A or B.Examples:Input: A = 2, B […]

Continue ReadingMinimize divisions by 2, 3, or 5 required to make two given integers equal Given two integers X and Y, the task is to make X and Y equal by dividing either of X or Y by 2, 3, or 5, minimum number of times, if found to be divisible. If the two integers can […]

Continue Readingdef GCD(a, b): if not b: return a return GCD(b, a % b) def GCDArr(a): ans = a[0] for i in a: ans = GCD(ans, i) return ans def findSubseqUtil(a, b, ans, k, i): if len(ans) == len(a): if GCDArr(ans) == k: print(ans) return […]

Continue Reading