title: Largest Subsequence Gcd Greater 1
signature: largest_subsequence_gcd_greater_1 <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(10L, 18L, 22L, 22L, 22L, 29L, 30L, 32L, 33L, 34L, 37L, 39L, 40L, 41L, 44L, 47L, 49L, 50L, 50L, 51L, 53L, 67L, 69L, 70L, 71L, 71L, 73L, 75L, 78L, 80L, 81L, 82L, 91L, 91L, 93L, 97L, 97L, 99L), 35L, 
          16L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-42L, 62L, 6L, 98L, 38L, -4L, -38L, 72L, 42L, 4L, -22L, -94L, 78L, -90L, 14L), 10L, 
          10L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 23L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(89L, 92L, 96L, 71L, 24L, 27L, 18L, 19L, 41L, 1L, 45L, 8L), 7L, 
          4L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -94L, -92L, -90L, -82L, -80L, -76L, -76L, -72L, -62L, -60L, -58L, -56L, -52L, -42L, -36L, -32L, -32L, -24L, -22L, -20L, -10L, -10L, -10L, -8L, -2L, -2L, 0L, 2L, 4L, 6L, 6L, 8L, 10L, 14L, 18L, 22L, 26L, 30L, 46L, 46L, 62L, 68L, 74L, 78L, 82L, 86L, 86L), 40L, 
          40L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L), 41L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(4L, 8L, 10L, 10L, 11L, 17L, 18L, 25L, 32L, 33L, 34L, 37L, 40L, 41L, 44L, 47L, 47L, 52L, 63L, 77L, 85L, 87L, 89L, 89L, 91L, 95L, 96L, 98L), 23L, 
          10L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-86L, 52L, -48L, 70L, 10L, -94L, 16L, 14L, 38L, 62L), 9L, 
          9L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 30L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(95L, 32L, 87L, 37L, 86L, 71L, 30L, 88L, 96L, 52L, 88L, 92L, 79L, 86L, 19L, 5L, 74L, 67L), 13L, 
          8L
      )))
  
  }
  
  main()
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;
  }