给定一个数N ,任务是找到第N个庚庚二酮数。
A Heptacontadigon Number is a class of figurate numbers. It has a 72-sided polygon called Heptacontadigon. The N-th Heptacontadigon number count’s the 72 number of dots and all other dots are surrounding with a common sharing corner and make a pattern. The first few Heptacontadigonol numbers are 1, 72, 213, 424, …
例子:
Input: N = 2
Output: 72
Explanation:
The second Heptacontadigonol number is 72.
Input: N = 3
Output: 213
方法:第N个庚庚二酮数由下式给出:
- S面多边形的第N个项=
- 因此,第72个面的第N个项由下式给出:
下面是上述方法的实现:
C/C++
// C++ program for the above approach
#include
using namespace std;
// Function to find the N-th
// Heptacontadigon Number
int HeptacontadigonNum(int N)
{
return (70 * N * N - 68 * N)
/ 2;
}
// Driver Code
int main()
{
// Given number N
int N = 3;
// Function Call
cout << HeptacontadigonNum(N);
return 0;
}
Java
// Java program for the above approach
class GFG{
// Function to find the N-th
// Heptacontadigon Number
static int HeptacontadigonNum(int N)
{
return (70 * N * N - 68 * N) / 2;
}
// Driver code
public static void main(String[] args)
{
int N = 3;
System.out.println(HeptacontadigonNum(N));
}
}
// This code is contributed by Pratima Pandey
Python3
# Python3 program for the above approach
# Function to find the N-th
# Heptacontadigon Number
def HeptacontadigonNum(N):
return (70 * N * N - 68 * N) // 2;
# Driver Code
# Given number N
N = 3;
# Function Call
print(HeptacontadigonNum(N));
# This code is contributed by Code_Mech
C#
// C# program for the above approach
using System;
class GFG{
// Function to find the N-th
// Heptacontadigon Number
static int HeptacontadigonNum(int N)
{
return (70 * N * N - 68 * N) / 2;
}
// Driver code
public static void Main()
{
int N = 3;
Console.Write(HeptacontadigonNum(N));
}
}
// This code is contributed by Code_Mech
输出:
213
时间复杂度: O(1)