CF47A Triangular numbers

题意翻译

给定一个数n,问你是否存在一个整数i,满足i*(i+1)/2=n。

若存在,输出"YES",否则输出"NO".

1<=n<=500

Translated by @稀神探女

题目描述

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 nn -th triangular number is the number of dots in a triangle with nndots 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 nn ( 1<=n<=5001<=n<=500 ) — the given integer.

 

输出格式:

 

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

 

输入输出样例

输入样例#1: 复制
1
输出样例#1: 复制
YES
输入样例#2: 复制
2
输出样例#2: 复制
NO
输入样例#3: 复制
3
输出样例#3: 复制
YES

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        if(i*i+i==2*n){
            cout<<"YES";
            return 0;
        }
    cout<<"NO";
}

 

转载于:https://www.cnblogs.com/cangT-Tlan/p/8442541.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值