Number of moves required to guess a permutation . | C ++ implementation of the approach ; Function that returns the required moves ; Final move ; Driver Program to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countMoves ( int n ) { int ct = 0 ; for ( int i = 1 ; i <= n ; i ++ ) ct += i * ( n - i ) ; ct += n ; return ct ; } int main ( ) { int n = 3 ; cout << countMoves ( n ) ; return 0 ; }