题解 CF47A 【Triangular numbers】

这题其实就是高斯求和问题,即1+...+x=x(x+1)/2。

由此,我们就可以用递推的思想来解决问题:

include<bits/stdc++.h>

using namespace std;

int main() {

  //freopen("ask.in","r",stdin);
  //freopen("ask.out","w",stdout);
  long long n,r=0;
  cin>>n;
  for(int i=1;i<=999;++i)
  {
      r+=i;
      if(r==n)
      {
          cout<<"YES";//如果成立
          return 0;
      }
      if(r>n)
      {
          cout<<"NO";//如果大于了n,则之后的r也必大于n,所以不成立。
          return 0;
      }
  }
  return 0;

}

原文地址:https://www.cnblogs.com/ThinkofBlank/p/10146186.html

时间: 2024-11-06 07:14:43

题解 CF47A 【Triangular numbers】的相关文章

LeetCode题解 || Add Two Numbers 问题

problem: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 ->

PAT甲级题解-1100. Mars Numbers (20)-字符串处理

没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是"hel",而不是"hel tret". 代码: #include <iostream> #include <cstdio> #include <algorithm> #include <map> #include <string> #include <string.h> using namespace s

Triangular Sums

描述 The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number of points in a triangular array with n points on side. For example T(4): XX XX X XX X X X Write a program to compute the weighted sum of triangular n

南阳122(Triangular Sums)

Triangular Sums 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number of points in a triangular array with n points on side. For example T(4): XX XX X XX X X X Write a

POJ 3086 Triangular Sums

Triangular Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6371   Accepted: 4529 Description The nth Triangular number, T(n) = 1 + - + n, is the sum of the first n integers. It is the number of points in a triangular array with n po

Funky Numbers CodeForces - 192A

As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular

2016 省赛热身 2016

2016 Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description In mathematics, a polygonal number is a number represented as dots or pebbles arranged in the shape of a regular polygon. The dots are thought of as alphas (u

【具体数学 读书笔记】1.2 Lines in the Plane

本节介绍平面划分问题,即n条直线最多把一个平面划分为几个区域(region). 问题描述: "What is the maximum number Ln of regions defined by n lines in the plane?" 这个问题最初由瑞士数学家Jacob Steiner在1826年解决. 延续上一节的解题步骤,即首先关注小规模数据,观察出结果,然后猜测一个递推式并从理论上证明,最后由递推式导出"closed form"(通项式).下面具体整理

cf 47A

F - Triangular numbers Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 47A Appoint description:  System Crawler  (2015-01-09) Description A triangular number is the number of dots in an