Open In App

Icosihenagonal Number

Last Updated : 17 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Given a number N, the task is to find Nth Icosihenagonal number.
 

An Icosihenagonal number is class of figurate number. It has 21 – sided polygon called Icosihenagon. The n-th Icosihenagonal number counts the 21 number of dots and all others dots are surrounding with a common sharing corner and make a pattern. The first few Icosihenagonal numbers are 1, 21, 60, 118, 195, 291, 406 … 
 


Examples: 
 

Input: N = 2 
Output: 21 
Explanation: 
The second Icosihenagonal number is 21
Input: N = 6 
Output: 291 
 


 


 


Approach: In mathematics, the Nth Icosihenagonal number is given by the formula: 
 

Tn = (19n^2 - 17n)/2


Below is the implementation of the above approach:
 

C++

// C++ program to find nth
// Icosihenagonal number
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to find
// Icosihenagonal number
int Icosihenagonal_num(int n)
{
    // Formula to calculate nth
    // Icosihenagonal number
    return (19 * n * n - 17 * n) / 2;
}
 
// Driver Code
int main()
{
    int n = 3;
    cout << Icosihenagonal_num(n) << endl;
 
    n = 10;
    cout << Icosihenagonal_num(n) << endl;
 
    return 0;
}

                    

Java

// Java program to find nth
// Icosihenagonal number
class GFG{
 
// Function to find
// Icosihenagonal number
static int Icosihenagonal_num(int n)
{
    // Formula to calculate nth
    // Icosihenagonal number
    return (19 * n * n - 17 * n) / 2;
}
 
// Driver Code
public static void main(String[] args)
{
    int n = 3;
    System.out.print(Icosihenagonal_num(n) + "\n");
 
    n = 10;
    System.out.print(Icosihenagonal_num(n) + "\n");
}
}
 
// This code is contributed by Rajput-Ji

                    

Python3

# Python3 program to find nth
# icosihenagonal number
 
# Function to find
# icosihenagonal number
def Icosihenagonal_num(n):
     
    # Formula to calculate nth
    # icosihenagonal number
    return (19 * n * n - 17 * n) / 2
     
# Driver Code
n = 3
print(int(Icosihenagonal_num(n)))
 
n = 10
print(int(Icosihenagonal_num(n)))
 
# This code is contributed by divyeshrabadiya07

                    

C#

// C# program to find nth
// Icosihenagonal number
using System;
 
class GFG{
 
// Function to find
// Icosihenagonal number
static int Icosihenagonal_num(int n)
{
    // Formula to calculate nth
    // Icosihenagonal number
    return (19 * n * n - 17 * n) / 2;
}
 
// Driver Code
public static void Main()
{
    int n = 3;
    Console.Write(Icosihenagonal_num(n) + "\n");
 
    n = 10;
    Console.Write(Icosihenagonal_num(n) + "\n");
}
}
 
// This code is contributed by Code_Mech

                    

Javascript

<script>
 
    // Javascript program to find nth
    // Icosihenagonal number
     
    // Function to find
    // Icosihenagonal number
    function Icosihenagonal_num(n)
    {
        // Formula to calculate nth
        // Icosihenagonal number
        return (19 * n * n - 17 * n) / 2;
    }
     
    let n = 3;
    document.write(Icosihenagonal_num(n) + "</br>");
   
    n = 10;
    document.write(Icosihenagonal_num(n));
     
</script>

                    

Output: 
60
865

 

Reference: https://en.wikipedia.org/wiki/Polygonal_number


 



Similar Reads

Program to check if N is a Icosihenagonal number
Given an integer N, the task is to check if it is a Icosihenagonal number or not. Icosihenagonal number is class of figurate number. It has 21 – sided polygon called Icosihenagon. The n-th Icosihenagonal number counts the 21 number of dots and all others dots are surrounding with a common sharing corner and make a pattern. The first few Icosihenago
4 min read
Check Whether a Number is an Anti Prime Number(Highly Composite Number)
Given a positive integer N, the task is to tell whether it's an anti-prime number or not. Anti-Prime Numbers (Highly Composite Number): A positive integer that has more divisors than any positive number smaller than it, is called an Anti-Prime Number (also known as Highly Composite Number). Following is the list of the first 10 anti-prime numbers a
5 min read
Number of factors of very large number N modulo M where M is any prime number
Given a large number N, the task is to find the total number of factors of the number N modulo M where M is any prime number. Examples: Input: N = 9699690, M = 17 Output: 1 Explanation: Total Number of factors of 9699690 is 256 and (256 % 17) = 1Input: N = 193748576239475639, M = 9 Output: 8 Explanation: Total Number of factors of 9699690 is 256 an
8 min read
Permutation of a number whose sum with the original number is equal to another given number
Given two integers A and C, the task is to check if there exists a permutation of the number A such that the sum of the number A and its permutation is equal to C. Examples: Input: A = 133, C = 446Output: YesExplanation: One of the permutation of A is 313. Therefore, sum = 133 + 313 = 446, which is equal to C. Input: A = 200, C = 201Output: No Naiv
6 min read
Minimum number of moves to make M and N equal by repeatedly adding any divisor of number to itself except 1 and the number
Given two numbers N and M, the task is to find the minimum number of moves to change N to M or -1 if it's impossible. In one move, add to the current number any of its divisors not equal to 1 and the number itself. Examples: Input: N = 4, M = 24Output: 5Explanation: the number 24 can be reached starting from 4 using 5 operations: 4-&gt;6-&gt;8-&gt;
16 min read
Given a number as a string, find the number of contiguous subsequences which recursively add up to 9
Given a number as a string, write a function to find the number of substrings (or contiguous subsequences) of the given string which recursively add up to 9. Example: Digits of 729 recursively add to 9, 7 + 2 + 9 = 18 Recur for 18 1 + 8 = 9 Examples: Input: 4189 Output: 3 There are three substrings which recursively add to 9. The substrings are 18,
6 min read
Number of times the largest perfect square number can be subtracted from N
Given a number N. At every step, subtract the largest perfect square( ? N) from N. Repeat this step while N &gt; 0. The task is to count the number of steps that can be performed. Examples: Input: N = 85 Output: 2 First step, 85 - (9 * 9) = 4 Second step 4 - (2 * 2) = 0 Input: N = 114 Output: 4 First step, 114 - (10 * 10) = 14 Second step 14 - (3 *
7 min read
Program to calculate the number of odd days in given number of years
Given an integer N, the task is to find the number of odd days in the years from 1 to N. Odd Days: Number of odd days refer to those days that are left in a certain year(s) when it's days gets converted into weeks. Say, an ordinary year has 365 days, that is 52 weeks and one odd day. This means, out of the 365 days in an ordinary year, 364 days wil
7 min read
Check if given number is Emirp Number or not
An Emirp Number (prime spelled backwards) is a prime number that results in a different prime when its decimal digits are reversed. This definition excludes the related palindromic primes. Examples : Input : n = 13Output : 13 is Emirp!Explanation :13 and 31 are both prime numbers. Thus, 13 is an Emirp number.Input : n = 27Output : 27 is not Emirp.O
10 min read
Given a number N in decimal base, find number of its digits in any base (base b)
Given A Number n in a base 10, find the number of digits in its base b representation. Constraints : [Tex]N \in \mathbb{W} [/Tex]Whole Examples : Input : Number = 48 Base = 4 Output: 3 Explanation : (48)10 = (300)4 Input : Number = 1446 Base = 7 Output: 4 Explanation : (446)10 = (4134)7 A simple approach: convert the decimal number into the given b
8 min read
Article Tags :
Practice Tags :