给定一个整数N ,任务是检查它是否是一个余弦数。如果数字N是余角数字,则打印“是”,否则打印“否” 。
Icosagonal Number is a twenty-sided polygon. The number derived from the figurative class. There are different patterns observed in this series. The dots are countable, arrange in a specific way of position, and create a diagram. All the dots have common dots points, all other dots are connected to these points and except this common point the dots connected to their ith dots with their respective successive layer… The first few Icosagonal numbers are 1, 20, 57, 112, 185, 276…
例子:
Input: N = 20
Output: Yes
Explanation:
Second Icosagonal Number is 20.
Input: N = 30
Output: No
方法:
1.在K的20边数个术语被给定为
2.由于我们必须检查给定的数字是否可以表示为二十角线数字。可以按以下方式检查–
=>
=>
3.如果使用上述公式计算出的K的值为整数,则N为二十等角数。
4.否则,数字N不是余角线数。
下面是上述方法的实现:
C++
// C++ program for the above approach
#include
using namespace std;
// Function to check if the number
// N is a icosagonal number
bool iicosagonal(int N)
{
float n
= (16 + sqrt(144 * N + 256))
/ 36;
// Condition to check if the
// N is a icosagonal number
return (n - (int)n) == 0;
}
// Driver Code
int main()
{
// Given Number
int N = 20;
// Function call
if (iicosagonal(N)) {
cout << "Yes";
}
else {
cout << "No";
}
return 0;
}
Java
// Java program for the above approach
import java.util.*;
class GFG{
// Function to check if the number
// N is a icosagonal number
static boolean iicosagonal(int N)
{
float n = (float)((16 + Math.sqrt(144 * N +
256)) / 36);
// Condition to check if the
// N is a icosagonal number
return (n - (int)n) == 0;
}
// Driver Code
public static void main(String[] args)
{
// Given Number
int N = 20;
// Function call
if (iicosagonal(N))
{
System.out.print("Yes");
}
else
{
System.out.print("No");
}
}
}
// This code is contributed by Rohit_ranjan
Python3
# Python3 program for the above approach
import numpy as np
# Function to check if the number
# N is a icosagonal number
def iicosagonal(N):
n = (16 + np.sqrt(144 * N + 256)) / 36
# Condition to check if the
# N is a icosagonal number
return (n - int(n)) == 0
# Driver Code
N = 20
# Function call
if (iicosagonal(N)):
print ("Yes")
else:
print ("No")
# This code is contributed by PratikBasu
C#
// C# program for the above approach
using System;
class GFG{
// Function to check if the number
// N is a icosagonal number
static bool iicosagonal(int N)
{
float n = (float)((16 + Math.Sqrt(144 * N +
256)) / 36);
// Condition to check if the
// N is a icosagonal number
return (n - (int)n) == 0;
}
// Driver Code
public static void Main(string[] args)
{
// Given Number
int N = 20;
// Function call
if (iicosagonal(N))
{
Console.Write("Yes");
}
else
{
Console.Write("No");
}
}
}
// This code is contributed by rutvik_56
Yes
时间复杂度: O(1)
辅助空间: O(1)