Nicomachusâ €™ s Theorem ( Sum of k | CPP program to find sum of k - th group of positive odd integers . ; Return the sum of k - th group of positive odd integers . ; Finding first element of kth group . ; Finding the sum . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int kthgroupsum ( int k ) { int cur = ( k * ( k - 1 ) ) + 1 ; int sum = 0 ; while ( k -- ) { sum += cur ; cur += 2 ; } return sum ; } int main ( ) { int k = 3 ; cout << kthgroupsum ( k ) << endl ; return 0 ; }