# Tag Archives: GCD-LCM

## Smallest number divisible by n and has at-least k trailing zerosSeptember 21, 2017

Two integers n and k are given. Our task is to print K-rounding of n. K-rounding is the minimum positive integer X, such that x… Read More »

## Check whether right angled triangle is valid or not for large sidesAugust 23, 2017

Given three integers a, b and c as triplets. Check if it is possible to make right angled triangle or not. Print Yes if possible,… Read More »

## Find pair with maximum GCD in an arrayJuly 23, 2017

We are given an array of positive integers. Find the pair in array with maximum GCD. Examples: Input : arr[] : { 1 2 3… Read More »

## Count number of pairs (A <= N, B <= N) such that gcd (A , B) is BJuly 12, 2017

Given a number n. We need find the number of ordered pairs of a and b such gcd(a, b) is b itself Examples: Input :… Read More »

## Minimum steps to come back to starting point in a circular tourJune 22, 2017

Consider circular track with n points marked as 1, 2, …n. A person is initially placed on point k. The person moves m > 0,… Read More »

## Given GCD G and LCM L, find number of possible pairs (a, b)June 20, 2017

We need to find number of possible pairs (a, b) such that GCD(a, b) is equal to given G and LCM (a, b) such that… Read More »

## Count total divisors of A or B in a given rangeJune 16, 2017

Given four integers m, n, a, b. Find how many integers from range m to n are divisible by a or b. Input: 3 11… Read More »

## Largest Subset with GCD 1June 10, 2017

Given n integers, we need to find size of the largest subset with GCD equal to 1. Input Constraint : n <= 10^5 A[i] <=… Read More »

## Maximum sum of distinct numbers such that LCM of these numbers is NJune 4, 2017

Given a positive number N. The task is to find maximum sum of distinct numbers such that the LCM of all these numbers is equal… Read More »

## Check if LCM of array elements is divisible by a prime number or notMay 30, 2017

Given an array and a number k, the task is to find if LCM of the array is divisible by k or not. Examples: Input… Read More »

## Queries for GCD of all numbers of an array except elements in a given rangeMay 26, 2017

Given an array of n numbers and a number of queries are also given. Each query will be represented by two integers l, r. The… Read More »

## Finding LCM of more than two (or array) numbers without using GCDApril 18, 2017

Given an array of positive integers, find LCM of the elements present in array. Examples: Input : arr[] = {1, 2, 3, 4, 28} Output… Read More »

## GCD of more than two (or array) numbersMarch 27, 2017

Given an array of numbers, find GCD of the array elements. In a previous post we find GCD of two number. Examples: Input : arr[]… Read More »

## Summation of GCD of all the pairs up to NMarch 11, 2017

Given a number N, find sum of all GCDs that can be formed by selecting all the pairs from 1 to N. Input : 4… Read More »

## Largest subsequence having GCD greater than 1March 3, 2017

Given an array arr[], find the largest subsequence such that GCD of all those subsequence are greater than 1. For exampple:- Input: 3, 6, 2,… Read More »