给定整数N ,任务是检查N是否是四角形数。如果数字N是四边形数字,则打印“是”,否则打印“否” 。
Tetradecagonal Number is 14-sided polygon called Tetrakaidecagon or Tetradecagon and belongs to the figurative number. The nth tetradecagonal number doted with some dots and create a series of the pattern. They have a common sharing corner point and doted with their spaces to each other. The dots continue with nth nested loop.The first few Tetradecagonal Numbers are 1, 14, 39, 76, 125, 186, …
例子:
Input: N = 14
Output: Yes
Explanation:
Second tetradecagonal number is 14.
Input: N = 40
Output: No
方法:
- 十四角数的第K个项为
- 因为我们必须检查给定的数字是否可以表示为四角形数。可以检查为:
=>
=>
- 如果使用上述公式计算出的K的值为整数,则N为四方对角数。
- 其他N不是四角形数。
下面是上述方法的实现:
C++
Java
Python3
C#
Javascript
输出: