给定数字N ,任务是找到第N个icosikaipentagon数。
An icosikaipentagon number is class of figurate number. It has 25- sided polygon called icosikaipentagon. The N-th icosikaipentagon number count’s the 25 number of dots and all others dots are surrounding with a common sharing corner and make a pattern. The first few icosikaipentagonol numbers are 1, 25, 72, 142 …
例子:
Input: N = 2
Output: 25
Explanation:
The second icosikaipentagonol number is 25.
Input: N = 3
Output: 72
方法:第N个二十烷五角形数由下式给出:
- S面多边形的第N个项=
- 因此,25个面的多边形的第N个项由下式给出:
下面是上述方法的实现:
C++
// C++ program to find the N-th
// Icosikaipentagon Number
#include
using namespace std;
// Function to find the N-th
// icosikaipentagon Number
int icosikaipentagonNum(int N)
{
return (23 * N * N - 21 * N)
/ 2;
}
// Driver code
int main()
{
int n = 3;
cout << "3rd icosikaipentagon Number is "
<< icosikaipentagonNum(n);
return 0;
}
Java
// Java program to find N-th
// icosikaipentagon number
class GFG{
// Function to find the nth
// icosikaipentagon number
static int icosikaipentagonNum(int N)
{
return (23 * N * N - 21 * N) / 2;
}
// Driver code
public static void main(String[] args)
{
int n = 3;
System.out.print("3rd icosikaipentagon Number is " +
icosikaipentagonNum(n));
}
}
// This code is contributed by shubham
Python3
# Python3 program to find the N-th
# icosikaipentagon number
# Function to find the N-th
# icosikaipentagon number
def icosikaipentagonNum(N):
return (23 * N * N - 21 * N) // 2
# Driver code
n = 3
print("3rd icosikaipentagon Number is ",
icosikaipentagonNum(n))
# This code is contributed by yatinagg
C#
// C# program for the above approach
using System;
class GFG{
// Finding the nth chiliagon number
static int Icosikaipentagon(int n)
{
return (23 * n * n - 21 * n) / 2;
}
// Driver code
public static void Main()
{
int n = 3;
Console.Write("3rd Icosikaipentagon Number is = " +
Icosikaipentagon(n));
}
}
// This code is contributed by shivanisinghss2110
Javascript
输出:
3rd icosikaipentagon Number is 72
时间复杂度: O(1)
辅助空间: O(1)
参考: http : //www.2dcurves.com/line/linep.html