Find permutation with maximum remainder Sum | C ++ implementation of the approach ; Function to find the permutation ; Put n at the first index 1 ; Put all the numbers from 2 to n sequentially ; Driver code ; Display the permutation
#include <bits/stdc++.h> NEW_LINE using namespace std ; vector < int > Findpermutation ( int n ) { vector < int > a ( n + 1 ) ; a [ 1 ] = n ; for ( int i = 2 ; i <= n ; i ++ ) a [ i ] = i - 1 ; return a ; } int main ( ) { int n = 8 ; vector < int > v = Findpermutation ( n ) ; for ( int i = 1 ; i <= n ; i ++ ) cout << v [ i ] << ' ▁ ' ; return 0 ; }