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. 学会使用DNSPod,仅需三步

    学会使用DNSPod,仅需三步   第一步:在DNSPod添加记录 1.访问 https://www.dnspod.cn网站,在DNSPod官网首页的右上角,有[注册],如下图所示,点击[注册]按钮 ...

  2. 文件哈希审计工具md5deep/hashdeep

    文件哈希审计工具md5deep/hashdeep   在数据取证中,通常需要验证文件的哈希值,以判断文件是否已知好文件,或者文件是否被修改过.Kali Linux提供专用工具hashdeep.该工具的 ...

  3. C# 简单读写ini文件帮助类 INIHelp

    软件里需要读取一些初始化信息, 决定用ini来做,简单方便. 于是查了一写代码,自己写了一个帮助类. INI文件格式是某些平台或软件上的配置文件的非正式标准, 以节(section)和键(key)构成 ...

  4. 使用IIS实现反向代理

    IIS的反向代理是通过ARR模块来完成的,ARR模块需要另外安装,而且只能通过Web PlatForm Installer安装.关于安装来源与步骤,帖子已有很多,不做描述.启用“Application ...

  5. 渗透测试中的bypass技巧

    0x00 前言 许多朋友在渗透测试中因为遇到WAF而束手无策,本人应邀,与godkiller一同写下此文,希望能够对许多朋友的问题有所帮助. 此系列一共分为五篇文章,分别如下: 一.架构层绕过WAF ...

  6. 【BZOJ-3123】森林 主席树 + 启发式合并

    3123: [Sdoi2013]森林 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 2738  Solved: 806[Submit][Status] ...

  7. C#高级编程9-第6章 数组

    数组 1.同一类型和不同类型的多个对象 需要使用同一类型的多个对象则使用集合和数组. Array类为数组元素排序和过滤提供了多个方法,使用枚举器,可以迭代数组所有元素. 2.简单数组 数组的声明 因为 ...

  8. ROS知识(19)----写一个简单的pluginlib例子

    参考资料: 官方教程:Writing and Using a Simple Plugin

  9. 数据表-java类的映射

    1.一个数据表对应一个java类 2.数据表的字段对应java类的属性 3.一对多的数据表关系 一方用一个java对象表示 多方用一个java对象数组表示 4.多对多的数据表关系:采用中间表,将多对多 ...

  10. [置顶] iOS中让省略号垂直居中

    在显示等待框时,一般要求在提示信息后面加个省略号,但中文输入法下输入的省略号是在底部对齐,但中 文的习惯是省略号垂直居中对齐,最后找到下面这个方法来显示垂直居中的省略号: 中文和英文输入法下一样: o ...