codeparrot/xlcost-text-to-code huggingface dataset:
Maximum number of 0 s that can be flipped such that Array has no adjacent 1 s | Java program for the above approach ; Maximum number of 0 s that can be replaced by 1 ; Check for three consecutive 0 s ; Flip the bit ; Increase the count ; Driver code
public class geeks { public static int canReplace ( int [ ] array ) { int i = 0 , count = 0 ; while ( i < array . length ) { if ( array [ i ] == 0 && ( i == 0 array [ i - 1 ] == 0 ) && ( i == array . length - 1 array [ i + 1 ] == 0 ) ) { array [ i ] = 1 ; count ++ ; } i ++ ; } return count ; } public static void main ( String [ ] args ) { int [ ] array = { 1 , 0 , 0 , 0 , 1 } ; System . out . println ( canReplace ( array ) ) ; } }
Sum of first N Star Numbers | Java program to find the sum of the first N star numbers ; Function to find the sum of the first N star number ; Variable to store the sum ; Driver code
class GFG { static int sum_star_num ( int n ) { int summ = 2 * n * ( n + 1 ) * ( n - 1 ) + n ; return summ ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( sum_star_num ( n ) ) ; } }
Count distinct median possible for an Array using given ranges of elements | Java implementation to count the number of distinct medians of an array where each array elements are given by a range ; Function to count the number of distinct medians of an array where each array elements are given by a range ; Loop to store the starting and end range in the array ; Condition to check if the length of the array is odd ; Driver Code ; Function call
import java . util . * ; import java . awt . * ; class GFG { static void solve ( int n , ArrayList < Point > vec ) { ArrayList < Integer > a = new ArrayList < > ( ) ; ArrayList < Integer > b = new ArrayList < > ( ) ; for ( Point pr : vec ) { a . add ( pr . x ) ; b . add ( pr . y ) ; } Collections . sort ( a ) ; Collections . sort ( b ) ; int left , right , ans ; if ( ( n & 1 ) != 0 ) { left = a . get ( n / 2 ) ; right = b . get ( n / 2 ) ; ans = right - left + 1 ; } else { left = ( a . get ( n / 2 ) + a . get ( n / 2 - 1 ) ) ; right = ( b . get ( n / 2 ) + b . get ( n / 2 - 1 ) ) ; ans = right - left + 1 ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int N = 3 ; ArrayList < Point > vec = new ArrayList < > ( ) ; vec . add ( new Point ( 100 , 100 ) ) ; vec . add ( new Point ( 10 , 10000 ) ) ; vec . add ( new Point ( 1 , 1000000000 ) ) ; solve ( N , vec ) ; } }
Count of pairs from Array with sum equal to twice their bitwise AND | Java implementation to find the pairs with equal sum and twice the bitwise AND of the pairs ; Map to store the occurrence of elements of array ; Function to find the pairs with equal sum and twice the bitwise AND of the pairs ; Loop to find the frequency of elements of array ; Function to find the count such pairs in the array ; If an element occurs more than once then the answer will by incremented by nC2 times ; Driver Code ; Function Call
import java . util . * ; class GFG { static HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; static int find_pairs ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } for ( Map . Entry < Integer , Integer > i : mp . entrySet ( ) ) { int count = i . getValue ( ) ; if ( count > 1 ) { ans += ( ( count * ( count - 1 ) ) / 2 ) ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 3 , 4 , 5 , 5 , 7 , 8 } ; int arr_size = arr . length ; System . out . print ( find_pairs ( arr , arr_size ) ) ; } }
360 | Java program for above approach ; Function to find the nth 360 - gon Number ; Driver code
class GFG { static int gonNum360 ( int n ) { return ( 358 * n * n - 356 * n ) / 2 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( gonNum360 ( n ) ) ; } }
120 | Java program for above approach ; Function to find the nth 120 - gon Number ; Driver code
class GFG { static int gonNum120 ( int n ) { return ( 118 * n * n - 116 * n ) / 2 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( gonNum120 ( n ) ) ; } }
Tetracontaoctagonal Number | Java program for above approach ; Function to find the nth TetracontaoctagonalNum Number ; Driver code
class GFG { static int TetracontaoctagonalNum ( int n ) { return ( 46 * n * n - 44 * n ) / 2 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( TetracontaoctagonalNum ( n ) ) ; } }
257 | Java program for above approach ; Function to find the nth 257 - gon Number ; Driver code
class GFG { static int gonNum257 ( int n ) { return ( 255 * n * n - 253 * n ) / 2 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( gonNum257 ( n ) ) ; } }
Tetracontadigonal Number | Java implementation for the above approach ; Function to find the nth Tetracontadigonal Number ; Driver Code
import java . util . * ; class GFG { static int TetracontadigonalNum ( int n ) { return ( 40 * n * n - 38 * n ) / 2 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( TetracontadigonalNum ( n ) ) ; } }
Index of smallest triangular number with N digits | Java implementation of the above approach ; Function to return index of smallest triangular no n digits ; Driver code
class GFG { static double findIndex ( int n ) { double x = Math . sqrt ( 2 * Math . pow ( 10 , ( n - 1 ) ) ) ; return Math . round ( x ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( findIndex ( n ) ) ; } }
Program to find the LCM of two prime numbers | Java Program to find LCM of two prime numbers ; Function to return the LCM of two prime numbers ; If the two numbers are equal then return any one of a and b ; Else return product of numbers ; Driver code ; Given two numbers ; Function Call
class GFG { static int findLCMPrime ( int a , int b ) { if ( a == b ) { return a ; } return a * b ; } public static void main ( String [ ] args ) { int a = 3 , b = 5 ; System . out . println ( findLCMPrime ( a , b ) ) ; } }
Smallest multiple of N with exactly N digits in its Binary number representation | Java program to find smallest multiple of n with exactly N digits in Binary Number System . ; Function to find smallest multiple of n with exactly N digits in Binary Number System . ; Driver code
class GFG { static void smallestNumber ( int N ) { System . out . print ( N * Math . ceil ( Math . pow ( 2 , ( N - 1 ) ) / N ) ) ; } public static void main ( String [ ] args ) { int N = 3 ; smallestNumber ( N ) ; } }
Find the largest N digit multiple of N | Java program to find largest multiple of N containing N digits ; Function to find the largest N digit multiple of N ; Driver code
import java . util . * ; class GFG { static void smallestNumber ( int N ) { System . out . print ( N * Math . floor ( ( Math . pow ( 10 , N ) - 1 ) / N ) ) ; } public static void main ( String args [ ] ) { int N = 2 ; smallestNumber ( N ) ; } }
Icosikaiheptagonal Number | Java program to find N - th icosikaiheptagonal number ; Function to find the nth icosikaiheptagonal number ; Driver code
class GFG { static int icosikaiheptagonalNum ( int n ) { return ( 25 * n * n - 23 * n ) / 2 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( "3rd ▁ icosikaiheptagonal ▁ Number ▁ is ▁ " + icosikaiheptagonalNum ( n ) ) ; } }
Program to check if N is a triacontagonal number | Java program to check whether a number is an triacontagonal number or not ; Function to check whether a number is an triacontagonal number or not ; Condition to check whether a number is an triacontagonal number or not ; Driver code ; Given number ; Function call
class GFG { static boolean istriacontagonal ( int N ) { float n = ( float ) ( ( 26 + Math . sqrt ( 224 * N + 676 ) ) / 56 ) ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int N = 30 ; if ( istriacontagonal ( N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }
Check whether one root of the Quadratic Equation is twice of other or not | Java program to check if one root of a quadratic equation is twice of other or not ; Function to find the required answer ; Driver Code
class GFG { static void checkSolution ( int a , int b , int c ) { if ( 2 * b * b == 9 * a * c ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { int a = 1 , b = 3 , c = 2 ; checkSolution ( a , b , c ) ; } }
Parity of the given mathematical expression using given N numbers | Java program to determine the parity of the given mathematical expression ; Iterating through the given integers ; If any odd number is present , then S is even parity ; Else , S is odd parity ; Driver code
class GFG { static void getParity ( int n , int [ ] A ) { for ( int x : A ) { if ( ( x & 1 ) == 1 ) { System . out . println ( " Even " ) ; return ; } } System . out . println ( " Odd " ) ; } public static void main ( String [ ] args ) { int N = 3 ; int [ ] A = { 2 , 3 , 1 } ; getParity ( N , A ) ; } }
Count of digits after concatenation of first N positive integers | Java program to find the number of digits after concatenating the first N positive integers ; Function to find the number of digits after concatenating the first N positive integers ; Driver code
class GFG { static void numberOfDigits ( int N ) { int nod = ( int ) Math . floor ( Math . log10 ( N ) + 1 ) ; int toDecrease = ( int ) ( Math . pow ( 10 , nod ) - 1 ) / 9 ; System . out . print ( ( N + 1 ) * nod - toDecrease ) ; } public static void main ( String [ ] args ) { int N = 13 ; numberOfDigits ( N ) ; } }
Length of maximum product subarray | Java program to find maximum length subarray having non zero product ; Function that returns the maximum length subarray having non zero product ; zeroindex list to store indexex of zero ; If zeroindex list is empty then Maxlength is as size of array ; If zeroindex list is not empty ; first zero is on index 2 that means two numbers positive , before index 2 so as their product is positive to ; Checking for other indexex ; If the difference is greater than maxlen then maxlen is updated ; To check the length of remaining array after last zeroindex ; Driver code
import java . util . * ; class GFG { static void Maxlength ( int arr [ ] , int N ) { Vector < Integer > zeroindex = new Vector < Integer > ( ) ; int maxlen ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) zeroindex . add ( i ) ; } if ( zeroindex . size ( ) == 0 ) { maxlen = N ; } else { maxlen = ( int ) zeroindex . get ( 0 ) ; for ( int i = 0 ; i < zeroindex . size ( ) - 1 ; i ++ ) { if ( ( int ) zeroindex . get ( i + 1 ) - ( int ) zeroindex . get ( i ) - 1 > maxlen ) { maxlen = ( int ) zeroindex . get ( i + 1 ) - ( int ) zeroindex . get ( i ) - 1 ; } } if ( N - ( int ) zeroindex . get ( zeroindex . size ( ) - 1 ) - 1 > maxlen ) { maxlen = N - ( int ) zeroindex . get ( zeroindex . size ( ) - 1 ) - 1 ; } } System . out . println ( maxlen ) ; } public static void main ( String args [ ] ) { int N = 9 ; int arr [ ] = { 7 , 1 , 0 , 1 , 2 , 0 , 9 , 2 , 1 } ; Maxlength ( arr , N ) ; } }
Check if sum of exactly K elements of the Array can be odd or not | Java implementation of the above approach ; Function returns true if it is possible to have odd sum ; Counting number of odd and even elements ; Driver code
class GFG { static boolean isPossible ( int arr [ ] , int N , int K ) { int oddCount = 0 , evenCount = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { evenCount ++ ; } else { oddCount ++ ; } } if ( evenCount == N || ( oddCount == N && K % 2 == 0 ) || ( K == N && oddCount % 2 == 0 ) ) { return false ; } else { return true ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 8 } ; int K = 5 ; int N = arr . length ; if ( isPossible ( arr , N , K ) ) { System . out . println ( " Possible " ) ; } else { System . out . println ( " Not ▁ Possible " ) ; } } }
Find the last two digits of Factorial of a given Number | Java implementation to find last two digits factorial of a given number ; Function to print the last two digits of N ! ; For N >= 10 , N ! % 100 will always be 0 ; Calculating N ! % 100 ; Driver code
import java . util . * ; class GFG { static void lastTwoDigits ( double N ) { if ( N >= 10 ) { System . out . print ( "00" ) ; return ; } double fac = 1 ; for ( int i = 1 ; i <= N ; i ++ ) fac = ( fac * i ) % 100 ; System . out . print ( fac ) ; } public static void main ( String args [ ] ) { int N = 7 ; lastTwoDigits ( N ) ; } }
Product of N terms of a given Geometric series | Java program for the above approach ; Function to calculate product of geometric series ; Return the final product with the above formula ; Driver Code ; Given first term and common ratio ; Number of terms ; Function Call
class GFG { static float productOfGP ( float a , float r , int n ) { return ( float ) Math . pow ( a , n ) * ( float ) Math . pow ( r , n * ( n - 1 ) / 2 ) ; } public static void main ( String s [ ] ) { float a = 1 , r = 2 ; int N = 4 ; System . out . println ( productOfGP ( a , r , N ) ) ; } }
Product of N terms of a given Geometric series | Java program for the above approach ; Function to calculate product of N terms of geometric series ; Find the product of first and the last term ; Return the sqrt of the above expression to find the product ; Driver Code ; Given first term and common ratio ; Number of terms ; Function Call
import java . util . * ; class GFG { static float productOfGP ( float a , float r , int n ) { int an = ( int ) ( a * ( int ) ( Math . pow ( r , n - 1 ) ) ) ; return ( int ) Math . sqrt ( ( int ) Math . pow ( a * an , n ) ) ; } public static void main ( String args [ ] ) { float a = 1 , r = 2 ; int N = 4 ; System . out . print ( productOfGP ( a , r , N ) ) ; } }
Find two numbers such that difference of their squares equal to N | Java Program to find two numbers with difference of their squares equal to N ; Function to check and print the required two positive integers ; Iterate till sqrt ( n ) to find factors of N ; Check if x is one of the factors of N ; Store the factor ; Compute the other factor ; Check if the two factors are of the same parity ; Compute a and b ; If no pair exists ; Driver Code
import java . util . * ; class GFG { static void solve ( int n ) { for ( int x = 1 ; x <= Math . sqrt ( n ) ; x ++ ) { if ( n % x == 0 ) { int small = x ; int big = n / x ; if ( small % 2 == big % 2 ) { int a = ( small + big ) / 2 ; int b = ( big - small ) / 2 ; System . out . print ( a + " ▁ " + b ) ; return ; } } } System . out . print ( - 1 ) ; } public static void main ( String args [ ] ) { int n = 7 ; solve ( n ) ; } }
Probability that an arbitrary positive divisor of 10 ^ X is an integral multiple of 10 ^ Y | Java program to find the probability of an arbitrary positive divisor of Xth power of 10 to be a multiple of Yth power of 10 ; Function to calculate and print the required probability ; Count of potential divisors of X - th power of 10 which are also multiples of Y - th power of 10 ; Count of divisors of X - th power of 10 ; Calculate GCD ; Print the reduced fraction probability ; Driver code
import java . util . * ; class GFG { static void prob ( int x , int y ) { int num = Math . abs ( x - y + 1 ) * Math . abs ( x - y + 1 ) ; int den = ( x + 1 ) * ( x + 1 ) ; int gcd = __gcd ( num , den ) ; System . out . print ( num / gcd + " / " + den / gcd + "NEW_LINE"); } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int X = 2 , Y = 1 ; prob ( X , Y ) ; } }
Program to check if N is a Chiliagon Number | Java program for the above approach ; Function to check that if N is Chiliagon Number or not ; Condition to check if N is a Chiliagon Number ; Driver Code ; Given Number ; Function call
class GFG { static boolean is_Chiliagon ( int N ) { float n = ( float ) ( 996 + Math . sqrt ( 7984 * N + 992016 ) ) / 1996 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String s [ ] ) { int N = 1000 ; if ( is_Chiliagon ( N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }
Count of common subarrays in two different permutations of 1 to N | Java implementation of the above approach ; Initialising Map for Index Mapping ; Mapping elements of A ; Modify elements of B according to Map ; Changing B [ i ] as the index of B [ i ] in A ; Count of common subarrays ; Traversing array B ; While consecutive elements are found , we increment K ; Add number of subarrays with length K to total count ; Driver code
class GFG { static int commonSubarrays ( int [ ] A , int [ ] B , int N ) { int [ ] Map = new int [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) Map [ A [ i ] ] = i ; for ( int i = 0 ; i < N ; i ++ ) { B [ i ] = Map [ B [ i ] ] ; } int count = 0 ; int i = 0 , K ; while ( i < N ) { K = 1 ; i += 1 ; while ( i < N && B [ i ] == B [ i - 1 ] + 1 ) { i += 1 ; K += 1 ; } count = count + ( ( K ) * ( K + 1 ) ) / 2 ; } return count ; } public static void main ( String [ ] args ) { int N = 3 ; int A [ ] = { 1 , 2 , 3 } ; int B [ ] = { 2 , 3 , 1 } ; System . out . print ( commonSubarrays ( A , B , N ) ) ; System . out . print ( "NEW_LINE"); N = 5 ; int C [ ] = { 1 , 2 , 3 , 4 , 5 } ; int D [ ] = { 2 , 3 , 1 , 4 , 5 } ; System . out . print ( commonSubarrays ( C , D , N ) ) ; } }
Represent N as sum of K even or K odd numbers with repetitions allowed | Java implementation to find an array of size K with all the even or odd elements in the array ; Function to find the array with all the even / odd elements ; First let 's check  kth is odd or even ; If last element is also an odd number then we can choose odd elements for our answer ; Add 1 in the array ( k - 1 ) times ; Add last odd element ; If array of even elements would be the answer then k - 1 elements would be 2 ; If last element is also an even number then we can choose even elements for our answer ; Add 2 in the array ( k - 1 ) times ; Add last even element ; Printing the array ; Driver code
import java . util . * ; class GFG { static void getArrayOfSizeK ( int n , int k ) { Vector < Integer > ans = new Vector < Integer > ( ) ; int odd = n - ( ( k - 1 ) * 1 ) ; if ( odd > 0 && odd % 2 != 0 ) { for ( int i = 0 ; i < k - 1 ; i ++ ) { ans . add ( 1 ) ; } ans . add ( odd ) ; } int even = n - ( ( k - 1 ) * 2 ) ; if ( even > 0 && even % 2 == 0 && ans . size ( ) == 0 ) { for ( int i = 0 ; i < k - 1 ; i ++ ) { ans . add ( 2 ) ; } ans . add ( even ) ; } if ( ans . size ( ) > 0 ) { for ( int i = 0 ; i < k ; i ++ ) { System . out . print ( ans . get ( i ) + " ▁ " ) ; } } else { System . out . println ( " NO " ) ; } } public static void main ( String args [ ] ) { int n = 10 , k = 3 ; getArrayOfSizeK ( n , k ) ; } }
Check whether a given number N is a Nude Number or not | Java program to check if the number if Nude number or not ; Check if all digits of num divide num ; array to store all digits of the given number ; If any of the condition is true for any digit Then N is not a nude number ; Driver code
import java . util . * ; class GFG { static boolean checkDivisbility ( int num ) { int digit ; int N = num ; while ( num != 0 ) { digit = num % 10 ; num = num / 10 ; if ( digit == 0 N % digit != 0 ) return false ; } return true ; } public static void main ( String [ ] args ) { int N = 128 ; boolean result = checkDivisbility ( N ) ; if ( result ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }
Hensel 's Lemma | Java program to illustrate the Hensel 's Lemma ; Function to find the modular inverse of a modulo m ; Apply the Euclidean algorithm , to find the modular inverse ; Function to find the derivative of f ( x ) and f '(x) = 3 * (x ^ 2) ; Function to find the image of x in f ( x ) = x ^ 3 - k . ; Function to find the next power of the number ; Next power of prime for which solution is to be found ; Using Hensel 's recursion to  find the solution (next_a) for  next power of prime ; If next_a < 0 return equivalent positive remainder modulo p ; Return the next power of a ; Function to find the solution of the required exponent of prime ; The lemma does not work for derivative of f ( x ) at a1 ; Looping from 1 to power of prime whose solution is to be found ; Final answer after evaluating all the exponents up till the required exponent ; Driver Code ; Function Call
import java . util . * ; class GFG { static int inv ( int a , int m ) { int m0 = m , t , q ; int x0 = 0 , x1 = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { q = a / m ; t = m ; m = a % m ; a = t ; t = x0 ; x0 = x1 - q * x0 ; x1 = t ; } if ( x1 < 0 ) x1 += m0 ; return x1 ; } static int derivative ( int x ) { return 3 * x * x ; } static int Image ( int x , int k ) { return x * x * x - k ; } static int next_power ( int a_t , int t , int a1 , int prime , int k ) { int power_p = ( int ) Math . pow ( prime , t + 1 ) ; int next_a = ( a_t - Image ( a_t , k ) * inv ( derivative ( a1 ) , prime ) ) % power_p ; if ( next_a < 0 ) return next_a += power_p ; return next_a ; } static int powerOfPrime ( int prime , int power , int k , int a1 ) { if ( derivative ( a1 ) != 0 ) { int a_t = a1 ; for ( int p = 1 ; p < power ; p ++ ) { a_t = next_power ( a_t , p , a1 , prime , k ) ; } return a_t ; } return - 1 ; } public static void main ( String [ ] args ) { int prime = 7 , a1 = 3 ; int power = 2 , k = 3 ; System . out . print ( powerOfPrime ( prime , power , k , a1 ) ) ; } }
Count of numbers with all digits same in a given range | Java program to count the total numbers in the range L and R which have all the digit same ; Function that count the total numbersProgram between L and R which have all the digit same ; Length of R ; tmp has all digits as 1 ; For each multiple of tmp in range 1 to 9 , check if it present in range [ L , R ] ; Increment the required count ; Driver code
import java . util . * ; class GFG { static int count_same_digit ( int L , int R ) { int tmp = 0 , ans = 0 ; int n = ( int ) Math . log10 ( R ) + 1 ; for ( int i = 0 ; i < n ; i ++ ) { tmp = tmp * 10 + 1 ; for ( int j = 1 ; j <= 9 ; j ++ ) { if ( L <= ( tmp * j ) && ( tmp * j ) <= R ) { ans ++ ; } } } return ans ; } public static void main ( String [ ] args ) { int L = 12 , R = 68 ; System . out . println ( count_same_digit ( L , R ) ) ; } }
Minimum LCM of all pairs in a given array | Java program to find the pair having minimum LCM ; Function that return pair having minimum LCM ; Find max element in the array as the gcd of two elements from the array can 't greater than max element. ; Created a 2D array to store minimum two multiple of any particular i . ; We already found two smallest multiple ; Iterating over all gcd ; Iterating over its multiple ; If we already found the two smallest multiple of i ; Choosing smallest two multiple ; Calculating lcm ; Return final answer ; Driver code
import java . util . Vector ; class GFG { static int minLCM ( int arr [ ] , int n ) { int mx = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mx = Math . max ( mx , arr [ i ] ) ; } Vector < Integer > [ ] mul = new Vector [ mx + 1 ] ; for ( int i = 0 ; i < mul . length ; i ++ ) mul [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mul [ arr [ i ] ] . size ( ) > 1 ) { continue ; } mul [ arr [ i ] ] . add ( arr [ i ] ) ; } for ( int i = 1 ; i <= mx ; i ++ ) { for ( int j = i + i ; j <= mx ; j += i ) { if ( mul [ i ] . size ( ) > 1 ) { break ; } for ( int k : mul [ j ] ) { if ( mul [ i ] . size ( ) > 1 ) break ; mul [ i ] . add ( k ) ; } } } int ans = Integer . MAX_VALUE ; for ( int i = 1 ; i <= mx ; i ++ ) { if ( mul [ i ] . size ( ) <= 1 ) continue ; int a = mul [ i ] . get ( 0 ) , b = mul [ i ] . get ( 1 ) ; int lcm = ( a * b ) / i ; ans = Math . min ( ans , lcm ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 3 , 6 , 5 } ; int n = arr . length ; System . out . print ( minLCM ( arr , n ) + "NEW_LINE"); } }