static int solve ( String s , int i , int j ) {
  int k ;
  long num = convert ( s , i , j ) ;
  if ( isprime ( num ) ) {
    return 0 ;
  }
  if ( i == j && isprime ( num ) ) return 0 ;
  if ( i == j && isprime ( num ) == false ) return Integer . MAX_VALUE ;
  if ( dp [ i ] [ j ] != 0 ) return dp [ i ] [ j ] ;
  int ans = Integer . MAX_VALUE ;
  for ( k = i ;
  k < j ;
  k ++ ) {
    int left = solve ( s , i , k ) ;
    if ( left == Integer . MAX_VALUE ) {
      continue ;
    }
    int right = solve ( s , k + 1 , j ) ;
    if ( right == Integer . MAX_VALUE ) {
      continue ;
    }
    ans = Math . min ( ans , 1 + left + right ) ;
  }
  return dp [ i ] [ j ] = ans ;
}

static int solve ( String s , int i , int j ) { int k ; long num = convert ( s , i , j ) ; if ( isprime ( num ) ) { return 0 ; } if ( i == j && isprime ( num ) ) return 0 ; if ( i == j && isprime ( num ) == false ) return Integer . MAX_VALUE ; if ( dp [ i ] [ j ] != 0 ) return dp [ i ] [ j ] ; int ans = Integer . MAX_VALUE ; for ( k = i ; k < j ; k ++ ) { int left = solve ( s , i , k ) ; if ( left == Integer . MAX_VALUE ) { continue ; } int right = solve ( s , k + 1 , j ) ; if ( right == Integer . MAX_VALUE ) { continue ; } ans = Math . min ( ans , 1 + left + right ) ; } return dp [ i ] [ j ] = ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier))))) (if_statement condition: (parenthesized_expression (method_invocation name: (identifier) arguments: (argument_list (identifier)))) consequence: (block (return_statement (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (method_invocation name: (identifier) arguments: (argument_list (identifier))))) consequence: (return_statement (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier))) right: (false)))) consequence: (return_statement (field_access object: (identifier) field: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (decimal_integer_literal))) consequence: (return_statement (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (for_statement init: (assignment_expression left: (identifier) right: (identifier)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) consequence: (block (continue_statement))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) consequence: (block (continue_statement))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (identifier)))))))) (return_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (identifier)))))