Find the largest possible k | C ++ program to find the largest possible k - multiple set ; Function to find the largest possible k - multiple set ; Sort the given array ; To store k - multiple set ; Traverse through the whole array ; Check if x / k is already present or not ; Print the k - multiple set ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void K_multiple ( int a [ ] , int n , int k ) { sort ( a , a + n ) ; set < int > s ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( a [ i ] % k == 0 && s . find ( a [ i ] / k ) == s . end ( ) ) a [ i ] % k != 0 ) s . insert ( a [ i ] ) ; } for ( auto i = s . begin ( ) ; i != s . end ( ) ; i ++ ) { cout << * i << " ▁ " ; } } int main ( ) { int a [ ] = { 2 , 3 , 4 , 5 , 6 , 10 } ; int k = 2 ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; K_multiple ( a , n , k ) ; return 0 ; }