http://codeforces.com/problemset/problem/47/A

Triangular numbers
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 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 test(s)
input
1
output
YES
input
2
output
NO
input
3
output
YES

用一个哈希表存储哪些是
triangular number,满足这个数字的要求就是这个数能由公式得到。

AC代码:
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int p[200000]; int main()
{
int n,i,x;
memset(p,0,sizeof(p));
for(i = 1; i <= 500; i++)
{
x = i*(i+1)/2;
p[x] = 1;
}
while(scanf("%d",&n)!=EOF)
{
if(p[n] == 1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
} return 0;
}

Triangular numbers的更多相关文章

  1. CF47A Triangular numbers

    CF47A Triangular numbers 题意翻译 给定一个数n,问你是否存在一个整数i,满足i*(i+1)/2=n. 若存在,输出"YES",否则输出"NO&q ...

  2. Triangular Sums

    描述 The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number ...

  3. codeforces 192A Funky Numbers

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

  4. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  5. Triangular Sums 南阳acm122

    Triangular Sums 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 The nth Triangular number, T(n) = 1 + … + n ...

  6. Gamma函数是如何被发现的?

    学过微积分的人,肯定都接触过Euler积分,按教科书上的说法,这是两种含有参变量的定积分,但其实没那么玄乎,它们只是两个函数.其中第一型Euler积分叫\(B\)-函数,第二型Euler积分叫\(\G ...

  7. 32-语言入门-32-Triangular Sums

    题目地址: http://acm.nyist.net/JudgeOnline/problem.php?pid=122    描述The nth Triangular number, T(n) = 1 ...

  8. The Hundred Greatest Theorems

    The Hundred Greatest Theorems The millenium seemed to spur a lot of people to compile "Top 100& ...

  9. 【南阳OJ分类之语言入门】80题题目+AC代码汇总

    小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...

随机推荐

  1. Django的Form机制小问题

    使用Django,我们可以以声明式的方式来定义一个Form,如下: 1 2 3 4 5 # -*- coding: utf-8 -*- from django import forms class S ...

  2. django创建model

    1.model实例 #!/usr/bin/python # coding:utf-8 from __future__ import unicode_literals from django.db im ...

  3. [BZOJ2815][ZJOI2012]灾难(拓扑排序/支配树)

    支配树目前只见到这一个应用,那就不独分一类,直接作为拓扑排序题好了. 每个点向所有食物连边,定义fa[x]为x的支配点,即离x最近的点,满足若fa[x]灭绝,则x也要灭绝. 这样,将fa[x]向x连边 ...

  4. BZOJ 3130: [Sdoi2013]费用流 网络流 二分 最大流

    https://www.lydsy.com/JudgeOnline/problem.php?id=3130 本来找费用流的题,权当复习一下网络流好了. 有点麻烦的是double,干脆判断大小或者二分增 ...

  5. bzoj 1934 最小割

    收获: 1.流量为0的边可以不加入. 2.最小割方案要与决策方案对应. #include <cstdio> #include <cmath> #include <cstr ...

  6. Jmeter实现对mysql的增、删、改、查

    1.          创建一个存储过程,语句如下: DELIMITER $$; DROP PROCEDURE IF EXISTS test; create PROCEDURE test() BEGI ...

  7. 如何让浮动的元素换行??css

    当你想要做成这种布局效果的时候 紫色框里面的内容那样 它是一个列表 li元素是块级元素  默认大小是父元素ul的宽 并且换行 如果li没有背景的话那就不用管了 可是问题来了它不但有背景 而且是根据文字 ...

  8. mysql slock

    http://www.itdks.com/dakashuo/new/dakalive/detail/3888

  9. Apple Developer Registration and DUNS Number Not Accepted

    Now that I have my Mac and app source code. I’m ready to start working on my first app. The next ste ...

  10. 点赞和吐糟Adblock Plus~进阶教程

    前言:Adblock Plus后文都简称ABP,这是一篇ABP进阶教程!用ABP实现flashBlock和NoScript.推荐有相当基础的阅读.刚開始学习的人先看懂这里:http://adblock ...