Find the sum of the first N Centered Octagonal Number Last Updated : 01 Dec, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a number N, the task is to find the sum of the first N Centered Octagonal Numbers. The first few Centered Octagonal numbers are 1, 9, 25, 49, 81, 121, 169, 225, 289, 361 ... Examples: Input: N = 3 Output: 35 Explanation: 1, 9 and 25 are the first three Centered Octagonal numbers. Input: N = 5 Output: 165 Approach: Initially, we need to create a function that will help us to calculate the Nth centered octagonal numbers.Now, run a loop starting from 1 to N, to find ith centered octagonal numbers.Add all the above calculated centered octagonal numbers.Finally, display the sum of the first N-centered octagonal numbers. Below is the implementation of the above approach: C++ // C++ program to find the sum of the // first N centered octagonal number #include<bits/stdc++.h> using namespace std; // Function to find the N-th centered // octagonal number int center_Octagonal_num(int n) { // Formula to calculate // nth centered octagonal // number return (4 * n * n - 4 * n + 1); } // Function to find the sum of the first // N centered octagonal numbers int sum_center_Octagonal_num(int n) { // Variable to store // the sum int summ = 0; // Iterating through the range // 1 to N for(int i = 1; i < n + 1; i++) { summ += center_Octagonal_num(i); } return summ; } // Driver Code int main() { int n = 5; cout << (sum_center_Octagonal_num(n)); return 0; } // This code is contributed by PratikBasu Java // Java program to find the sum of the // first N centered octagonal number class GFG { // Function to find N-th centered // octagonal number static int center_Octagonal_num(int n) { // Formula to calculate // nth centered octagonal // number return (4 * n * n - 4 * n + 1); } // Function to find the // sum of the first N // centered octagonal // numbers static int sum_center_Octagonal_num(int n) { // Variable to store // the sum int summ = 0; // Iterating through the first N // numbers for(int i = 1; i < n + 1; i++) { summ += center_Octagonal_num(i); } return summ; } // Driver code public static void main(String[] args) { int n = 5; System.out.println(sum_center_Octagonal_num(n)); } } // This code is contributed by Princi Singh Python3 # Python3 program to find the # sum of the first N # Centered Octagonal number # Function to find N-th # Centered Octagonal # number def center_Octagonal_num(n): # Formula to calculate # nth centered Octagonal # number return (4 * n * n - 4 * n + 1) # Function to find the # sum of the first N # Centered Octagonal # numbers def sum_center_Octagonal_num(n) : # Variable to store # the sum summ = 0 # Iterating through the first N # numbers for i in range(1, n + 1): summ += center_Octagonal_num(i) return summ # Driver code if __name__ == '__main__' : n = 5 print(sum_center_Octagonal_num(n)) C# // C# program to find the sum of the // first N centered octagonal number using System; class GFG{ // Function to find N-th centered // octagonal number static int center_Octagonal_num(int n) { // Formula to calculate // nth centered octagonal // number return (4 * n * n - 4 * n + 1); } // Function to find the sum of // the first N centered octagonal // numbers static int sum_center_Octagonal_num(int n) { // Variable to store // the sum int summ = 0; // Iterating through the first N // numbers for(int i = 1; i < n + 1; i++) { summ += center_Octagonal_num(i); } return summ; } // Driver code public static void Main() { int n = 5; Console.WriteLine(sum_center_Octagonal_num(n)); } } // This code is contributed by Akanksha_Rai JavaScript <script> // Javascript program to find the sum of the // first N centered octagonal number // Function to find the N-th centered // octagonal number function center_Octagonal_num(n) { // Formula to calculate // nth centered octagonal // number return (4 * n * n - 4 * n + 1); } // Function to find the sum of the first // N centered octagonal numbers function sum_center_Octagonal_num(n) { // Variable to store // the sum let summ = 0; // Iterating through the range // 1 to N for(let i = 1; i < n + 1; i++) { summ += center_Octagonal_num(i); } return summ; } let n = 5; document.write(sum_center_Octagonal_num(n)); </script> // This code is contributed by divyeshrabadiya07. Output165 Time Complexity: O(N)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Find the sum of the first N Centered Octagonal Number S SHUBHAMSINGH10 Follow Improve Article Tags : Mathematical DSA Practice Tags : Mathematical Similar Reads Find the sum of the first N Centered Octadecagonal Numbers Given a number N, the task is to find the sum of first N Centered Octadecagonal numbers.Examples: Input: N = 3 Output: 75 Explanation: 1, 19 and 55 are the first three centered octadecagonal numbers.Input: N = 10 Output: 298 Approach: Initially, we need to create a function which will help us to cal 4 min read Find the sum of the first N Centered Pentagonal Number Given a number N, the task is to find the sum of first N Centered Pentagonal Numbers. The first few Centered Pentagonal Number are 1, 6, 16, 31, 51, 76, 106 ⦠Examples: Input: N = 3 Output: 23 Explanation: 1, 6 and 16 are the first three Centered Pentagonal number.Input: N = 5 Output: 105 Approach: 5 min read Find the sum of the first Nth Centered Pentadecagonal Number Given a number N the task is to find the sum of the first N Centered Pentadecagonal Number. The first few Centered Pentadecagonal Numbers are 1, 16, 46, 91, 151, 226, 316 ... Examples: Input: N = 3 Output: 63 Explanation: 1, 16 and 46 are the first three centered pentadecagonal numbers. Input: N = 5 4 min read Find the sum of the first N Centered Dodecagonal Number Given a number N, the task is to find the sum of first N Centered Dodecagonal Number. The first few Centered Dodecagonal Numbers are 1, 13, 37, 73, 121, 181 ... Examples: Input: N = 3 Output: 51 Explanation: 1, 13 and 37 are the first three centered Dodecagonal number.Input: N = 5 Output: 245 Approa 4 min read Find the sum of the first N Centered Decagonal Numbers Given a number N, the task is to find the sum of the first N Centered Decagonal Numbers. The first few Centered decagonal numbers are 1, 11, 31, 61, 101, 151 ... Examples: Input: N = 3 Output: 43 Explanation: 1, 11 and 31 are the first three Centered decagonal numbers.Input: N = 5 Output: 205 Approa 5 min read Like