Given an integer n, find the nth Pentagonal number. First three pentagonal numbers are 1, 5 and 12 (Please see below diagram).
The n’th pentagonal number Pn is the number of distinct dots in a pattern of dots consisting of the outlines of regular pentagons with sides up to n dots, when the pentagons are overlaid so that they share one vertex [Source Wiki]
Input: n = 1 Output: 1 Input: n = 2 Output: 5 Input: n = 3 Output: 12
In general, a polygonal number (triangular number, square number, etc) is a number represented as dots or pebbles arranged in the shape of a regular polygon. The first few pentagonal numbers are: 1, 5, 12, etc.
If s is the number of sides in a polygon, the formula for the nth s-gonal number P (s, n) is
nth s-gonal number P(s, n) = (s - 2)n(n-1)/2 + n If we put s = 5, we get n'th Pentagonal number Pn = 3*n*(n-1)/2 + n
Below are the implementations of above idea in different programming languages.
10th Pentagonal Number is = 145
This article is contributed by Mazhar Imam Khan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Centered pentagonal number
- Pentagonal Pyramidal Number
- Program to check if N is a Pentagonal Number
- Program to find volume and surface area of pentagonal prism
- Count number of triplets with product equal to given number with duplicates allowed
- Find minimum number to be divided to make a number a perfect square
- Count number of trailing zeros in Binary representation of a number using Bitset
- Smallest number dividing minimum number of elements in the array | Set 2
- Largest number dividing maximum number of elements in the array
- Smallest number dividing minimum number of elements in the Array
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Number of ways to split a binary number such that every part is divisible by 2
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Given number of matches played, find number of teams in tournament
- Number of times the largest perfect square number can be subtracted from N
Improved By : jit_t