Given a number n , the task is to find nth Centered Square Number.
Centered Square Number is a centered figurate number that gives the number of dots in a square with a dot in the center and all other dots surrounding the center dot in successive square layers. Nth Centered square number can be calculated by using formula n2 + (n-1)2.
Input : n = 2 Output : 5 Input : n = 9 Output : 145
We can find n-th Centered Square Number using below formula.
n-th Centered Square Number = n2 + (n-1)2
How does this formula work?
If we take a closer look, we can notice that the n-th Centered Square Number can be seen as sum of two consecutive square numbers (1 dot, 4 dots, 9 dots, 16 dots, etc).
Below is the implementation :
7th Centered square number: 85
- Check if a number is perfect square without finding square root
- Centered cube number
- Centered dodecahedral number
- Centered tetrahedral number
- Centered Hexadecagonal Number
- Centered tridecagonal number
- Centered Octahedral number
- Centered Dodecagonal Number
- Centered pentagonal number
- Centered heptagonal number
- Centered nonadecagonal number
- Centered hexagonal number
- Centered Octadecagonal Number
- Centered Pentadecagonal Number
- Centered triangular number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : vt_m