二十碳六烯对角数是一类数字。它有29面的多边形,称为icosikaienneagon 。第N个icosikaienneagonal数是29个点,所有其他点都围绕着一个公共的共享角并形成图案。
前几个icosikaienneagonol编号为
1, 29, 84, 166 …
找出第N个二十烷碳对角线数
给定数N ,任务是找到第N个icosikaienneagonal数。
例子:
Input: N = 2
Output: 29
Explanation:
The second icosikaienneagonol number is 29.
Input: N = 3
Output: 84
方法:
- 在数学中,第N个s面多边形数由以下公式给出:
- 因此,第29面多边形的第N个项是
下面是上述方法的实现:
C++
// C++ implementation for
// above approach
#include
using namespace std;
// Function to Find the Nth
// icosikaienneagonal Number
int icosikaienneagonalNum(int n)
{
return (27 * n * n - 25 * n) / 2;
}
// Driver Code
int main()
{
int n = 3;
cout << icosikaienneagonalNum(n);
return 0;
}
Java
// Java implementation for
// above approach
class GFG{
// Function to Find the Nth
// icosikaienneagonal Number
static int icosikaienneagonalNum(int n)
{
return (27 * n * n - 25 * n) / 2;
}
// Driver Code
public static void main(String args[])
{
int n = 3;
System.out.print(icosikaienneagonalNum(n));
}
}
// This code is contributed by Code_Mech
Python 3
# Python3 implementation for
# above approach
# Function to Find the Nth
# icosikaienneagonal Number
def icosikaienneagonalNum(n):
return (27 * n * n - 25 * n) // 2
# Driver Code
# Given N
N = 3
print(icosikaienneagonalNum(N))
# This code is contributed by Vishal Maurya
C#
// C# implementation for
// above approach
using System;
class GFG{
// Function to Find the Nth
// icosikaienneagonal Number
static int icosikaienneagonalNum(int n)
{
return (27 * n * n - 25 * n) / 2;
}
// Driver Code
public static void Main()
{
int n = 3;
Console.Write(icosikaienneagonalNum(n));
}
}
// This code is contributed by Code_Mech
Javascript
输出:
84