VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-lcm-array-elements-divisible-prime-number-not/

⇱ Check if LCM of array elements is divisible by a prime number or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if LCM of array elements is divisible by a prime number or not

Last Updated : 23 Jul, 2025

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 : int[] a = {10, 20, 15, 25}
 k = 3
Output : true

Input : int[] a = {24, 21, 45, 57, 36};
 k = 23;
Output : false


 


One simple solution is to first find LCM of array elements, then check if LCM is divisible by k or not.
Here, without calculating the LCM of the number we can find that LCM of the array of number is divisible by a prime number k or not. If any number of the array is divisible by prime number k, then the LCM of the number is also divisible by prime number k.
 

Output : 
 

 true

Time Complexity: O(n) 
Auxiliary Space: O(1)


 

Comment