public static void main ( String [ ] args ) throws Exception {
  Scanner s = new Scanner ( new File ( "D.in" ) ) ;
  PrintWriter out = new PrintWriter ( new File ( "D.out" ) ) ;
  dpc [ 1 ] = 0 ;
  dpc [ 2 ] = 2 ;
  dpa [ 1 ] = 0 ;
  dpa [ 2 ] = 1 ;
  for ( int i = 3 ;
  i <= 1000 ;
  i ++ ) {
    dpc [ i ] = 1 ;
    for ( int j = 1 ;
    j < i ;
    j ++ ) {
      dpc [ i ] += ( dpc [ j ] + dpa [ i - j ] ) / i ;
    }
    dpc [ i ] *= ( ( double ) i ) / ( i - 1 ) ;
    dpa [ i ] = dpc [ i ] - 1 ;
  }
  int T = s . nextInt ( ) ;
  int [ ] arr = new int [ 1024 ] ;
  boolean [ ] mark = new boolean [ 1024 ] ;
  for ( int tc = 1 ;
  tc <= T ;
  tc ++ ) {
    out . print ( "Case #" + tc + ": " ) ;
    int N = s . nextInt ( ) ;
    for ( int i = 1 ;
    i <= N ;
    i ++ ) arr [ i ] = s . nextInt ( ) ;
    double answer = 0 ;
    Arrays . fill ( mark , false ) ;
    for ( int i = 1 ;
    i <= N ;
    i ++ ) {
      int cycleLength = 0 ;
      int cur = i ;
      while ( ! mark [ cur ] ) {
        mark [ cur ] = true ;
        cur = arr [ cur ] ;
        cycleLength ++ ;
      }
      answer += dpc [ cycleLength ] ;
    }
    out . println ( answer ) ;
  }
  out . close ( ) ;
  System . out . println ( dpc [ 1000 ] ) ;
}

public static void main ( String [ ] args ) throws Exception { Scanner s = new Scanner ( new File ( " D . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( " D . out " ) ) ; dpc [ 1 ] = 0 ; dpc [ 2 ] = 2 ; dpa [ 1 ] = 0 ; dpa [ 2 ] = 1 ; for ( int i = 3 ; i <= 1000 ; i ++ ) { dpc [ i ] = 1 ; for ( int j = 1 ; j < i ; j ++ ) { dpc [ i ] += ( dpc [ j ] + dpa [ i - j ] ) / i ; } dpc [ i ] *= ( ( double ) i ) / ( i - 1 ) ; dpa [ i ] = dpc [ i ] - 1 ; } int T = s . nextInt ( ) ; int [ ] arr = new int [ 1024 ] ; boolean [ ] mark = new boolean [ 1024 ] ; for ( int tc = 1 ; tc <= T ; tc ++ ) { out . print ( " Case ▁ # " + tc + " : ▁ " ) ; int N = s . nextInt ( ) ; for ( int i = 1 ; i <= N ; i ++ ) arr [ i ] = s . nextInt ( ) ; double answer = 0 ; Arrays . fill ( mark , false ) ; for ( int i = 1 ; i <= N ; i ++ ) { int cycleLength = 0 ; int cur = i ; while ( ! mark [ cur ] ) { mark [ cur ] = true ; cur = arr [ cur ] ; cycleLength ++ ; } answer += dpc [ cycleLength ] ; } out . println ( answer ) ; } out . close ( ) ; System . out . println ( dpc [ 1000 ] ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))))) right: (identifier)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (parenthesized_expression (cast_expression type: (floating_point_type) value: (identifier))) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (false)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) 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: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (while_statement condition: (parenthesized_expression (unary_expression operand: (array_access array: (identifier) index: (identifier)))) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (update_expression (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))))