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. python面向对象(封装,继承,多态)

    python面向对象(封装,继承,多态) 学习完本篇,你将会深入掌握 如何封装一个优雅的借口 python是如何实现继承 python的多态 封装 含义: 1.把对象的属性和方法结合成一个独立的单位, ...

  2. git tag标签

    列出标签 # 默认按字母排序显示 $ git tag # 模糊匹配查找标签 $ git tag -l "v2.8.5*" 创建标签 # 创建附注标签 $ git tag -a v1 ...

  3. Jmeter系列(6)- 分析源码,创建登录、浏览商品接口请求

    前言简介 接口的压力测试有个二八原则:线上80%的用户量在一天24小时20%(即4.8个小时)的时间里可以平稳运行,这个接口就算是通过压力测试了 源码分析 登录 浏览商品 创建请求 登录 浏览菜单 C ...

  4. 进入vim /etc/profile如何退出

    按o或i输入 按Esc,输入:wq,退出

  5. lumen-phpunit 单元测试

    lumen-框架5.8为例 1,把vendor下的bin目录放到环境变量里面: 2,设置路由 $router->get('syn', ['uses' => 'syn\syn@diction ...

  6. 《exe应用程序UI自动化》

    前言:有很多公司做一些客户端的应用,每次发版都要耗费人力去手动回归比较费时,那么我们就想着去怎么去驱动人为的操作变为机器的操作过程,当然想着进行UI自动 那么我们就要考虑怎么去实现exe应用程序的自动 ...

  7. 自己写登陆验证及借用auth的is_authenticated验证是否登陆

    一. 自己写登陆需要注册,一个session的处理,还有一个session的删除 #自定义一个闭包装饰器,来验证def checkLogin(func): def wrapper(request, * ...

  8. django forms的常用命令及方法(一)

    根据别人网上发布,个人爱好收集 Form表单的功能 自动生成HTML表单元素 检查表单数据的合法性 如果验证错误,重新显示表单(数据不会重置) 数据类型转换(字符类型的数据转换成相应的Python类型 ...

  9. vue1.0,2.0区别 生命周期

    1.生命周期  删除 beforeCompile compiled ready,新增beforeMounted mounted beforeUpdate updated 2.for循环里取消了$ind ...

  10. 定要过python二级选择题第一套

    1. 2.https://zhuanlan.zhihu.com/p/199883725 树,队列,二叉树,树的基本回忆 二叉树: 分叉为俩个;  一个是右子树一个是左子树 队列:先进先出 柞:后进先出 ...