码迷,mamicode.com
首页 > 其他好文 > 详细

cf 47A

时间:2015-01-10 20:56:57      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

F - Triangular numbers
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Appoint description: 

Description

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 n dots 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 Input

Input
1
Output
YES
Input
2
Output
NO
Input
3
Output
YES

 

 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
int t,n;
int main()
{
      while(scanf("%d",&t)!=EOF)
      {
            n=(int)sqrt(2*t);
            if(n*(n+1)==2*t)
                  printf("YES\n");
            else
                  printf("NO\n");
      }
      return 0;
}

  

cf 47A

标签:

原文地址:http://www.cnblogs.com/a972290869/p/4215566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!