给定整数N ,任务是检查N是否为十进制数。如果数字N是十进制数,则打印“是”,否则打印“否” 。
Hendecagonal Number is a figurate number that extends the concept of triangular and square numbers to the decagon(11-sided polygon). The nth hendecagonal number counts the number of dots in a pattern of n nested decagons, all sharing a common corner, where the ith hendecagon in the pattern has sides made of i dots spaced one unit apart from each other. The first few hendecagonal numbers are 1, 11, 30, 58, 95, 141…
例子:
Input: N = 11
Output: Yes
Explanation:
Second hendecagonal number is 11.
Input: N = 40
Output: No
方法:
- 十进制数的第K个项给出为
- 由于我们必须检查给定的数字是否可以表示为十进制数。可以检查为:
=>
=>
- 如果使用上述公式计算出的K值为整数,则N为一个十进制数。
- 其他N不是十进制数。
下面是上述方法的实现:
C++
// C++ program for the above approach
#include
using namespace std;
// Function to check if N is a
// Hendecagonal Number
bool ishendecagonal(int N)
{
float n
= (7 + sqrt(72 * N + 49))
/ 18;
// Condition to check if the
// number is a hendecagonal number
return (n - (int)n) == 0;
}
// Driver Code
int main()
{
// Given Number
int N = 11;
// Function call
if (ishendecagonal(N)) {
cout << "Yes";
}
else {
cout << "No";
}
return 0;
}
Java
// Java program for the above approach
import java.lang.Math;
class GFG{
// Function to check if N is a
// hendecagonal number
public static boolean ishendecagonal(int N)
{
double n = (7 + Math.sqrt(72 * N + 49)) / 18;
// Condition to check if the
// number is a hendecagonal number
return (n - (int)n) == 0;
}
// Driver code
public static void main(String[] args)
{
// Given number
int N = 11;
// Function call
if (ishendecagonal(N))
{
System.out.println("Yes");
}
else
{
System.out.println("No");
}
}
}
// This code is contributed by divyeshrabadiya07
Python3
# Python3 program for the above approach
import math
# Function to check if N is a
# Hendecagonal Number
def ishendecagonal(N):
n = (7 + math.sqrt(72 * N + 49))// 18;
# Condition to check if the
# number is a hendecagonal number
return (n - int(n)) == 0;
# Driver Code
# Given Number
N = 11;
# Function call
if (ishendecagonal(N)):
print("Yes");
else:
print("No");
# This code is contributed by Nidhi_biet
C#
// C# program for the above approach
using System;
class GFG{
// Function to check if N is a
// hendecagonal number
public static bool ishendecagonal(int N)
{
double n = (7 + Math.Sqrt(72 * N + 49)) / 18;
// Condition to check if the
// number is a hendecagonal number
return (n - (int)n) == 0;
}
// Driver code
public static void Main(string[] args)
{
// Given number
int N = 11;
// Function call
if (ishendecagonal(N))
{
Console.Write("Yes");
}
else
{
Console.Write("No\n");
}
}
}
// This code is contributed by rutvik_56
Javascript
输出:
Yes