Problem Description
Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the sum of the sub-sequence is M.
 
Input
Input contains multiple test cases. each case contains two integers N, M( 1 <= N, M <= 1000000000).input ends with N = M = 0.
 
Output
For each test case, print all the possible sub-sequence that its sum is M.The format is show in the sample below.print a blank line after each test case.

思路:

假设答案为[i,j],则有:j2+j-i2-i=2M   -->   (j+i+1)(j-i)=2M

对2M进行分解,,然后判断,,搞一搞,,

代码:

int n,m;

int main(){
while(cin>>n>>m,n||m){
m*=2;
int t=(int)sqrt(m+0.5);
rep2(i,t,1){
if(m%i==0){
int a,b;
a=m/i, b=i;
int x,y;
x=(a-b-1)/2;
y=(a+b-1)/2;
if(x<0 || y>n || (2*x+1)!=(a-b) || (2*y+1)!=(a+b)) continue;
printf("[%d,%d]\n",x+1,y);
}
}
cout<<endl;
}
}

hdu 2058 The sum problem(简单因式分解,,)的更多相关文章

  1. HDU 2058 The sum problem(枚举)

    The sum problem Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the ...

  2. 题解报告:hdu 2058 The sum problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2058 问题描述 给定一个序列1,2,3,...... N,你的工作是计算所有可能的子序列,其子序列的总 ...

  3. HDU 2058 The sum problem

    传送门 Description Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequen ...

  4. HDU 2058 The sum problem (数学+暴力)

    题意:给定一个N和M,N表示从1到N的连续序列,让你求在1到N这个序列中连续子序列的和为M的子序列区间. 析:很明显最直接的方法就是暴力,可是不幸的是,由于N,M太大了,肯定会TLE的.所以我们就想能 ...

  5. HDU 2058 The sum problem 数学题

    解题报告:可以说是一个纯数学题,要用到二元一次和二元二次解方程,我们假设[a,b]这个区间的所有的数的和是N,由此,我们可以得到以下公式: (b-a+1)*(a+b) / 2 = N;很显然,这是一个 ...

  6. HDU - 2058 The sum problem(思路题)

    题目: Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the ...

  7. hdu 2058 The sum problem(数学题)

    一个数学问题:copy了别人的博客 #include<cstdio> #include<cstdlib> #include<cmath> int main() { ...

  8. HDOJ 2058 The sum problem

    Problem Description Given a sequence 1,2,3,--N, your job is to calculate all the possible sub-sequen ...

  9. NYoj The partial sum problem(简单深搜+优化)

    题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=927 代码: #include <stdio.h> #include & ...

随机推荐

  1. CS:APP Chapter 3 程序的机器级表示-读书笔记

    3.1 程序的机器级表示 发展历史 Intel,AMD,ARM 等企业各有又是,CPU 从 8 位发展到 16 位,再到 32 位,近几年发展到 64 位,当下的 CPU 体系被称为 x86-64 体 ...

  2. PHP中的日期相关函数(二)

    上回文章中我们介绍了三个时间日期相关的对象,不过它们的出镜频率并不是特别地高.今天学习的对象虽说可能不少人使用过,但是它的出镜频率也是非常低的.它们其实就是我们非常常用的那些面向过程的日期函数的面向对 ...

  3. TP5多条件搜索,同时有必要条件

    $model = $this->model; // 查询是否有搜索参数 $search = input('?get.search') ? trim(input('get.search')) : ...

  4. python风格对象

    对象表示形式 python提供了两种获取对象字符串表示形式的标准方式 repr()         //便于开发者理解的方式返回对象的字符串表示形式(一般来说满足obj==eval(repr(obj) ...

  5. DeDeCMS v5.7 漏洞复现

    DedeCMS V5.7 漏洞复现 XSS漏洞 首先我们在首页要进行用户的注册以及登录 这里我们已经提前注册过了,登录即可 普通用户账号密码:root/passwd 管理员账号密码:admin/pik ...

  6. P3214-[HNOI2011]卡农【dp】

    正题 题目链接:https://www.luogu.com.cn/problem/P3214 题目大意 一个由\(1\sim n\)的所有整数构成的集合\(S\),求出它的\(m\)个不同非空子集满足 ...

  7. YbtOJ#903-染色方案【拉格朗日插值,NTT,分治】

    正题 题目链接:https://www.ybtoj.com.cn/contest/115/problem/3 题目大意 两个长度为\(n+1\)的序列\(a,b\) \(a_i\)表示涂了\(i\)个 ...

  8. P5540-[BalkanOI2011]timeismoney|最小乘积生成树【最小生成树,凸壳】

    正题 题目链接:https://www.luogu.com.cn/problem/P5540 题目大意 给出\(n\)个点\(m\)条边边权是一个二元组\((a_i,b_i)\),求出一棵生成树最小化 ...

  9. 千位分隔符的JS实现

    $.extend({ //千位分割符 MoneySeparator: function numFormat(num){ if(num==null){ return num; }else { num=n ...

  10. 几分钟就能学会的Python虚拟环境教程

    什么是虚拟环境 我们在使用Python的时候,通常用pip来进行包管理.比如我们要安装一个叫requests的库,那么我们就会采用以下命令去安装: pip install requests 那你知道, ...