A. Triangular numbers

来源:互联网 发布:淘宝运动服装 编辑:程序博客网 时间:2024/04/30 00:05

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with ndots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).

Your task is to find out if a given integer is a triangular number.

Input

The first line contains the single number n (1 ≤ n ≤ 500) — the given integer.

Output

If the given integer is a triangular number output YES, otherwise output NO.

Sample test(s)
input
1
output
YES
input
2
output
NO
input
3
output
YES


解题说明:关于什么是三角数请看这里:http://en.wikipedia.org/wiki/Triangular_number 判断一个数是不是三角数就只需要判断该数是否等于n(n+1)/2,由于输入不超过500,那么n值不超过33,暴力即可。


#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;int main(){int n,c=1,f=0;scanf("%d",&n);    for(;c<33;c++){if(n==c*(c+1)/2){f=1;}}if(f==1){printf("YES\n");}else{printf("NO\n");}}


原创粉丝点击