📜  癸基米角编号

📅  最后修改于: 2021-05-05 01:27:36             🧑  作者: Mango

给定数字N ,任务是找到N聚变体数。

例子:

方法:N个十进制的十边形数由下式给出:

  • S面多边形的第N个项= \frac{((S - 2)N^2 - (S - 4)N)}{2}
  • 因此,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)