title: Largest Subsequence Gcd Greater 1
signature: int largestSubsequenceGcdGreater1(vector<int> arr, int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({10, 18, 22, 22, 22, 29, 30, 32, 33, 34, 37, 39, 40, 41, 44, 47, 49, 50, 50, 51, 53, 67, 69, 70, 71, 71, 73, 75, 78, 80, 81, 82, 91, 91, 93, 97, 97, 99}, 35, 16); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-42, 62, 6, 98, 38, -4, -38, 72, 42, 4, -22, -94, 78, -90, 14}, 10, 10); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 23, 0); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({89, 92, 96, 71, 24, 27, 18, 19, 41, 1, 45, 8}, 7, 4); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-98, -94, -92, -90, -82, -80, -76, -76, -72, -62, -60, -58, -56, -52, -42, -36, -32, -32, -24, -22, -20, -10, -10, -10, -8, -2, -2, 0, 2, 4, 6, 6, 8, 10, 14, 18, 22, 26, 30, 46, 46, 62, 68, 74, 78, 82, 86, 86}, 40, 40); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1}, 41, 0); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({4, 8, 10, 10, 11, 17, 18, 25, 32, 33, 34, 37, 40, 41, 44, 47, 47, 52, 63, 77, 85, 87, 89, 89, 91, 95, 96, 98}, 23, 10); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-86, 52, -48, 70, 10, -94, 16, 14, 38, 62}, 9, 9); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 30, 0); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({95, 32, 87, 37, 86, 71, 30, 88, 96, 52, 88, 92, 79, 86, 19, 5, 74, 67}, 13, 8); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def largest_subsequence_gcd_greater_1(arr, n):
      ans = 0
      maxele = max(arr)
      for i in range(2, (maxele + 1)):
          count = 0
          for j in range(n):
              if ((arr[j] % i) == 0):
                  count += 1
          ans = max(ans, count)
      return ans
source_cpp: int largest_subsequence_gcd_greater_1(vector<int> arr, int n) {
    int ans = 0;
    int maxele = * max_element(arr.begin(), arr.end());
    for ( int i = 2;
    i <= maxele;
    ++ i ) {
      int count = 0;
      for ( int j = 0;
      j < n;
      ++ j ) {
        if ( arr [ j ] % i == 0 ) ++ count;
      }
      ans = max ( ans, count );
    }
    return ans;
  }