给定数N ,任务是找到第N个二十烷七角形数。
An icosikaiheptagonal number is a class of figurate numbers. It has 27 – sided polygon called icosikaiheptagon. The N-th icosikaiheptagonal number count’s the 27 number of dots and all other dots are surrounding with a common sharing corner and make a pattern. The first few icosikaiheptagonol numbers are 1, 27, 78, 154 …
例子:
Input: N = 2
Output: 27
Explanation:
The second icosikaiheptagonol number is 27.
Input: N = 3
Output: 78
方法:第N个二十烷七角形数由下式给出:
- 侧多边形的第N个项=
- 因此27个面的多边形的第N个项是
下面是上述方法的实现:
C++
// C++ program to find N-th
// icosikaiheptagonal number
#include
using namespace std;
// Function to find the nth
// icosikaiheptagonal Number
int icosikaiheptagonalNum(int n)
{
return (25 * n * n - 23 * n) / 2;
}
// Driver code
int main()
{
int n = 3;
cout << "3rd icosikaiheptagonal Number is "
<< icosikaiheptagonalNum(n);
return 0;
}
Java
// Java program to find N-th
// icosikaiheptagonal number
class GFG{
// Function to find the nth
// icosikaiheptagonal number
static int icosikaiheptagonalNum(int n)
{
return (25 * n * n - 23 * n) / 2;
}
// Driver code
public static void main(String[] args)
{
int n = 3;
System.out.print("3rd icosikaiheptagonal Number is " +
icosikaiheptagonalNum(n));
}
}
// This code is contributed by shubham
Python3
# Python3 program to find N-th
# icosikaiheptagonal number
# Function to find the nth
# icosikaiheptagonal Number
def icosikaiheptagonalNum(n):
return (25 * n * n - 23 * n) // 2;
# Driver code
n = 3;
print("3rd icosikaiheptagonal Number is ",
icosikaiheptagonalNum(n));
# This code is contributed by Code_Mech
C#
// C# program to find N-th
// icosikaiheptagonal number
using System;
class GFG{
// Function to find the nth
// icosikaiheptagonal number
static int icosikaiheptagonal(int n)
{
return (25 * n * n - 23 * n) / 2;
}
// Driver code
public static void Main(String[] args)
{
int n = 3;
Console.Write("3rd icosikaiheptagonal Number is " +
icosikaiheptagonal(n));
}
}
// This code is contributed by shivanisinghss2110
Javascript
输出:
3rd icosikaiheptagonal Number is 78
参考: http : //www.2dcurves.com/line/linep.html