题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1138

题意:中文题诶~

思路:假设 x=a1+(a1+1)+...+(a1+n-1)=n*a1+(n-1)*n/2;

所以:a1=(2*x-(n-1)*n)/(2*n);

那么我们只要枚举n就可以啦,接下来我们还有确定n的范围:

x=(a1+an)*n/2=(a1+a1+(n-1)*d)*n/2=(n+1)*n/2; 即(n+1)*n=2*x, 所以n<sqrt(2*x);

又,题目中要求n>=2,所以我们只要枚举n从sqrt(2*x)到2就好啦.....

代码:

 #include <bits/stdc++.h>
using namespace std; int main(void){
int x;
bool flag=true;
cin >> x;
int i=sqrt(*x);
while(i>=){
int gg=(*x-(i-)*i)/(2.0*i);
if(gg==(*x-(i-)*i)/(2.0*i)){
cout << gg << endl;
flag=false;
}
i--;
}
if(flag){
cout << "No Solution" << endl;
}
return ;
}

51nod1138(连续和)的更多相关文章

  1. [51nod1138]正整数分解为几个连续自然数之和

    解题关键:注意为什么上界是$\sqrt {2n} $ 因为函数是关于m的递减函数,而结果必须为正整数 $a = \frac{{2n + m - {m^2}}}{{2m}} = \frac{n}{m} ...

  2. Redis简单案例(三) 连续登陆活动的简单实现

    连续登陆活动,或许大家都不会陌生,简单理解就是用户连续登陆了多少天之后,系统就会送一些礼品给相应的用户.最常见的 莫过于游戏和商城这些.游戏就送游戏币之类的东西,商城就送一些礼券.正值国庆,应该也有不 ...

  3. C# if中连续几个条件判断

    C# if中连续几个条件判断 1.if (条件表达式1 && 条件表达式2) 当条件表达式1为true时 using System; using System.Collections. ...

  4. L1-006. 连续因子

    https://www.patest.cn/contests/gplt/L1-006 题目地址 在上面 一个正整数N的因子中可能存在若干连续的数字.例如630可以分解为3*5*6*7,其中5.6.7就 ...

  5. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  6. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  7. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  8. linux Mint18 backspace怎么不能连续删除

    打开菜单--->首选项--->键盘,如下图所示: 打开启用重复按键即可,就可以随心所欲的连续删除,连续移动光标了

  9. 剑指Offer面试题:28.连续子数组的最大和

    一.题目:连续子数组的最大和 题目:输入一个整型数组,数组里有正数也有负数.数组中一个或连续的多个整数组成一个子数组.求所有子数组的和的最大值.要求时间复杂度为O(n).例如输入的数组为{1,-2,3 ...

随机推荐

  1. Delphi - 数组和结构体

    技术交流,DH讲解. 记得很早之前我就说过,数组和结构体在内存中其实一样的,他们都是连续分布的.例如: ? 1 2 3 4 TMyStruct = record   A,B,C:Integer; en ...

  2. django中使用多个数据库,跨库查询

    一.settings配置多个数据库 DATABASES = { 'default': { # 'ENGINE': 'django.db.backends.mysql', 'ENGINE': 'comm ...

  3. 2018.5.29 从layout 到 PCBA

    1 Gerber 这个网上有现成的教程:(不要写网上能找到的资料-敏捷开发) AD 导出Gerber :https://jingyan.baidu.com/article/3c48dd3494181c ...

  4. 【转】C++11 标准新特性:Defaulted 和 Deleted 函数

    原文链接http://www.ibm.com/developerworks/cn/aix/library/1212_lufang_c11new/ 本文将介绍 C++11 标准的两个新特性:defaul ...

  5. 如何查看myeclipse是否激活

    myEclipse---->Subscription information--->Subscription expiration date 看这个日期到什么时候!另外建议别用太高版本的M ...

  6. ffmpeg命令选项解释

    ffmpeg作为媒体文件处理软件,基本用法如下: ffmpeg -i INPUTfile [OPTIONS] OUTPUTfile 输入输出文件通常就是待处理的多媒体文件了.可以是纯粹的音频文件,纯粹 ...

  7. hdu2196 Computer待续

    #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #i ...

  8. poj 2390 Bank Interest(计算本利和)

    一.Description Farmer John made a profit last year! He would like to invest it well but wonders how m ...

  9. Azure上部署FTP服务

    FTP是个比较复杂的协议,其协议分为控制层和数据层,工作模式分为主动和被动两种模式. 在默认的Active模式下其工作原理如下: 可以看到,客户端发起FTP的请求道服务器端,FTP的端口是21.用户在 ...

  10. 删除 char[10][10] 中的一行

    1. 描述 删除二维字符数组其中一行,并用下一行进行填补 2. 代码 #include <iostream> #include <string.h> using namespa ...