Find the permutation of first N natural numbers such that sum of i % Pi is maximum possible | C ++ implementation of the approach ; Function to find the permutation of the first N natural numbers such that the sum of ( i % Pi ) is maximum possible and return the maximum sum ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Max_Sum ( int n ) { return ( n * ( n - 1 ) ) / 2 ; } int main ( ) { int n = 8 ; cout << Max_Sum ( n ) ; return 0 ; }