给定数字N ,任务是找到第N个癸基十聚变体数。
A Decakismyriagon Number is a class of figurate numbers. It has a 100000-sided polygon called Decakismyriagon. The N-th Decakismyriagon Number counts the 100000 number of dots and all other dots are surrounding with a common sharing corner and make a pattern. The first few Decakismyriagonol Numbers are 1, 100000, 299997, 599992, …
例子:
Input: N = 2
Output: 100000
Explanation:
The second Decakismyriagonol number is 100000.
Input: N = 3
Output: 299997
方法:第N个十进制的十边形数由下式给出:
- S面多边形的第N个项=
- 因此,第100000个面多边形的第N个项由下式给出:
下面是上述方法的实现:
C / C++
C++
// C++ program for the above approach
#include
using namespace std;
// Function to find the N-th
// Decakismyriagon Number
int DecakismyriagonNum(int N)
{
return (99998 * N * N - 99996 * N)
/ 2;
}
// Driver Code
int main()
{
// Given Number N
int N = 3;
// Function Call
cout << DecakismyriagonNum(N);
return 0;
}
Java
// Java program for the above approach
class GFG{
// Function to find the N-th
// Decakismyriagon Number
static int DecakismyriagonNum(int N)
{
return (99998 * N * N - 99996 * N) / 2;
}
// Driver code
public static void main(String[] args)
{
// Given Number N
int N = 3;
// Function Call
System.out.println(DecakismyriagonNum(N));
}
}
// This code is contributed by Pratima Pandey
Python3
# Python3 program for the above approach
# Function to find the N-th
# Decakismyriagon Number
def DecakismyriagonNum(N):
return (99998 * N * N - 99996 * N) // 2;
# Driver Code
# Given Number N
N = 3;
# Function Call
print(DecakismyriagonNum(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
// Decakismyriagon Number
static int DecakismyriagonNum(int N)
{
return (99998 * N * N - 99996 * N) / 2;
}
// Driver code
public static void Main()
{
// Given Number N
int N = 3;
// Function Call
Console.Write(DecakismyriagonNum(N));
}
}
// This code is contributed by Code_Mech
Javascript
输出:
299997
时间复杂度: O(1)