GCD & LCM Coding Problems Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report Please refer Greatest Common Divisor (GCD) and Least Common Multiple (LCM) to know the background of these topics. Easy Problems on GCD and LCM: Program to find GCD or HCF of two numbers Program to find LCM of two numbers Least Common Denominator (LCD) GCD of digits of a given number GCD of array LCM of array Find LCM of rational numbers GCD of two numbers when one of them can be very large GCD of elements in a given range LCM of First n Natural Numbers LCM of digits of a given number Program to find HCF iteratively GCD, LCM and Distributive Property Medium Problems on GCD and LCM: Basic and Extended Euclidean algorithms Program to find GCD of floating point numbers HCF of array of fractions (or rational numbers) Pair with maximum GCD from two arrays LCM of factorial and its neighbors Largest subarray with GCD one Replace every matrix element with maximum of GCD of row or column Check if LCM of array elements is divisible by a prime number or not Print the kth common factor of two numbers Finding LCM of more than two (or array) numbers without using GCD Given GCD G and LCM L, find number of possible pairs (a, b) GCD of two numbers formed by n repeating x and y times Largest Subset with GCD 1 Count pairs of natural numbers with GCD equal to given number Hard Problems on GCD and LCM: Stein’s Algorithm for finding GCD Largest subsequence having GCD greater than 1 Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B Smallest number divisible by n and has at-least k trailing zeros Array with GCD of any of its subset belongs to the given array Find pair with maximum GCD in an array First N natural can be divided into two sets with given difference and co-prime sums Series with largest GCD and sum equals to n Maximum sum of distinct numbers with LCM as N Queries for GCD of all numbers of an array except elements in a given range Summation of GCD of all the pairs up to N Count number of subsets of a set with GCD equal to a given number Check if elements of array can be made equal by multiplying given prime numbers Quick Links: Recent articles on GCD and LCM Practice problems on Math Comment H harendrakumar123 Follow 1 Improve H harendrakumar123 Follow 1 Improve Article Tags : Mathematical DSA GCD-LCM Explore DSA FundamentalsLogic Building Problems 2 min read Analysis of Algorithms 1 min read Data StructuresArray Data Structure 3 min read String in Data Structure 2 min read Hashing in Data Structure 2 min read Linked List Data Structure 2 min read Stack Data Structure 2 min read Queue Data Structure 2 min read Tree Data Structure 2 min read Graph Data Structure 3 min read Trie Data Structure 15+ min read AlgorithmsSearching Algorithms 2 min read Sorting Algorithms 3 min read Introduction to Recursion 15 min read Greedy Algorithms 3 min read Graph Algorithms 3 min read Dynamic Programming or DP 3 min read Bitwise Algorithms 4 min read AdvancedSegment Tree 2 min read Binary Indexed Tree or Fenwick Tree 15 min read Square Root (Sqrt) Decomposition Algorithm 15+ min read Binary Lifting 15+ min read Geometry 2 min read Interview PreparationInterview Corner 3 min read GfG160 3 min read Practice ProblemGeeksforGeeks Practice - Leading Online Coding Platform 6 min read Problem of The Day - Develop the Habit of Coding 5 min read Like