text: Rearrange array to maximize sum of GCD of array elements with their respective indices | Java program to implement the above approach ; Function to find the maximum sum of GCD ( arr [ i ] , i ) by rearranging the array ; Stores maximum sum of GCD ( arr [ i ] , i ) by rearranging the array elements ; Update res ; Driver Code
code: import java . util . * ; class GFG { static int findMaxValByRearrArr ( int arr [ ] , int N ) { int res = 0 ; res = ( N * ( N + 1 ) ) / 2 ; return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 1 } ; int N = arr . length ; System . out . print ( findMaxValByRearrArr ( arr , N ) ) ; } }