Triangular numbers
http://codeforces.com/problemset/problem/47/A
2 seconds
256 megabytes
standard input
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.
The first line contains the single number n (1 ≤ n ≤ 500) — the given integer.
If the given integer is a triangular number output YES, otherwise output NO.
1
YES
2
NO
3
YES
用一个哈希表存储哪些是
triangular number,满足这个数字的要求就是这个数能由公式得到。
#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的更多相关文章
- CF47A Triangular numbers
CF47A Triangular numbers 题意翻译 给定一个数n,问你是否存在一个整数i,满足i*(i+1)/2=n. 若存在,输出"YES",否则输出"NO&q ...
- Triangular Sums
描述 The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number ...
- codeforces 192A Funky Numbers
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 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 ...
- Triangular Sums 南阳acm122
Triangular Sums 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 The nth Triangular number, T(n) = 1 + … + n ...
- Gamma函数是如何被发现的?
学过微积分的人,肯定都接触过Euler积分,按教科书上的说法,这是两种含有参变量的定积分,但其实没那么玄乎,它们只是两个函数.其中第一型Euler积分叫\(B\)-函数,第二型Euler积分叫\(\G ...
- 32-语言入门-32-Triangular Sums
题目地址: http://acm.nyist.net/JudgeOnline/problem.php?pid=122 描述The nth Triangular number, T(n) = 1 ...
- The Hundred Greatest Theorems
The Hundred Greatest Theorems The millenium seemed to spur a lot of people to compile "Top 100& ...
- 【南阳OJ分类之语言入门】80题题目+AC代码汇总
小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...
随机推荐
- 怎么处理stdClass::__set_state
处理后 处理方法 function object2array_pre(&$object) { if (is_object($object)) { $arr = (array)($object) ...
- CF1042C Array Product 分类讨论+贪心
考虑有无负数(负数的个数为奇视作“有”,否则为“无”)和有无零 无负数无零,全部合并即可 无负数有零,那么把零合并起来,删掉零 有负数无零,把最大的负数找出来,删掉,合并剩余的数 有负数有零,把零和最 ...
- BZOJ 2648 SJY摆棋子(KD树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2716 [题目大意] 给出一些点,同时不断插入点和询问某点离插入点最近距离 [题解] 我 ...
- 【堆优化Dijkstra】BZOJ4152- [AMPPZ2014]The Captain
[题目大意] 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. [思路] 按照某维坐标排序,相邻两个点在这一维度 ...
- Minimum Size Subarray Sum 最短子数组之和
题意 Given an array of n positive integers and a positive integer s, find the minimal length of a suba ...
- HDU 2089 不要62(数位DP·记忆化搜索)
题意 中文 最基础的数位DP 这题好像也能够直接暴力来做 令dp[i][j]表示以 j 开头的 i 位数有多少个满足条件 那么非常easy有状态转移方程 dp[i][j] = sum{ dp[ ...
- Tasker : Task / Shortcut Widgets
Task / Shortcut Widgets The standard way of running a Tasker task is by attaching it to a profile wh ...
- Linux下的两个经典宏定义 转
http://www.linuxidc.com/Linux/2016-08/134481.htm http://www.linuxidc.com/Linux/2013-01/78003.htm htt ...
- pytest文档25-conftest.py作用范围
前言 一个测试工程下是可以有多个conftest.py的文件,一般在工程根目录放一个conftest.py起到全局作用. 在不同的测试子目录也可以放conftest.py,作用范围只在该层级以及以下目 ...
- Java中List效率的比较
Java Collections Framework(JCF) 是Java SE中一个基本的类集,几乎所有的项目都会用到,其中的List 则是JCF中最最常用的一个接口.围绕List 接口,有很多实现 ...