Icosagonal number - GeeksforGeeks

16 Jul, 2021
Given a number n, the task is to find the nth Icosagonal number. An Icosagonal number is the 20-gon is a twenty-sided polygon. The number derived from the figurative class. There are different pattern series number in this number. The dots are countable, arrange in a specific way of position and create a diagram. All the dots have a common dots points, all others dots are connected to this points and except this common point the dots connected to their i-th dots with their respective successive layer.Examples :  
Input : 3 Output :57Input :8 Output :512  
 
Formula for nth icosagonal number:  
 
C++
Java
Python 3
C#
PHP
Javascript
// C++ program to find// nth Icosagonal number#include <bits/stdc++.h>using namespace std; // Function to calculate Icosagonal numberint icosagonal_poly(long int n){    // Formula for finding    // nth Icosagonal number    return (18 * n * n - 16 * n) / 2;} // Drivers codeint main(){    long int n = 7;    cout << n << "th Icosagonal number :"               << icosagonal_poly(n);     return 0;}
// Java program to find// nth Icosagonal number import java.io.*; class GFG {     // Function to calculate Icosagonal number static int icosagonal_poly(int n){    // Formula for finding    // nth Icosagonal number    return (18 * n * n - 16 * n) / 2;} // Drivers code         public static void main (String[] args) {        int n = 7;         System.out.print (n + "th Icosagonal number :");    System.out.println(icosagonal_poly(n));    }}// This code is contributed by aj_36
# Python 3 program to find# nth Icosagonal number # Function to calculate# Icosagonal numberdef icosagonal_poly(n) :         # Formula for finding    # nth Icosagonal number    return (18 * n * n -            16 * n) // 2 # Driver Codeif __name__ == '__main__' :    n = 7    print(n,"th Icosagonal number : ",                   icosagonal_poly(n)) # This code is contributed m_kit
// C# program to find// nth Icosagonal numberusing System; class GFG{ // Function to calculate// Icosagonal numberstatic int icosagonal_poly(int n){    // Formula for finding    // nth Icosagonal number    return (18 * n * n -            16 * n) / 2;} // Driver codestatic public void Main (){     int n = 7; Console.Write(n + "th Icosagonal " +                        "number :");Console.WriteLine(icosagonal_poly(n));}} // This code is contributed by ajit
<?php// PHP program to find// nth Icosagonal number // Function to calculate// Icosagonal numberfunction icosagonal_poly($n){    // Formula for finding    // nth Icosagonal number    return (18 * $n *            $n - 16 * $n) / 2;} // Driver Code$n = 7;echo $n , "th Icosagonal number :",               icosagonal_poly($n); // This code is contributed by ajit?>
<script>    // Javascript program to find nth Icosagonal number         // Function to calculate    // Icosagonal number    function icosagonal_poly(n)    {        // Formula for finding        // nth Icosagonal number        return (18 * n * n - 16 * n) / 2;    }         let n = 7;       document.write(n + "th Icosagonal number :");    document.write(icosagonal_poly(n));     </script>
Output :  
7th Icosagonal number :385
Time Complexity: O(1)Auxiliary Space: O(1)
Reference: https://en.wikipedia.org/wiki/Polygonal_number 
jit_t
mukesh07
manikarora059
number-theory
Geometric
Mathematical
number-theory
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
Equation of circle when three points on the circle are given
Convex Hull | Set 2 (Graham Scan)
Given n line segments, find if any two segments intersect
Closest Pair of Points | O(nlogn) Implementation
Program for Fibonacci numbers
Write a program to print all permutations of a given string
C++ Data Types
Set in C++ Standard Template Library (STL)
Coin Change | DP-7