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. scrum项目冲刺_day08总结

    摘要:今日完成任务. 1.短信服务正在进行 2.注册登录功能基本实现,但缺少短信验证 3.导航在进行 4.搜索功能基本完成 总任务: 一.appUI页面(已完成) 二.首页功能: 1.图像识别功能(已 ...

  2. linux7可以通过远程和localhost访问mysql,但是127.0.0.1不能访问

    网上搜索的其他方法都试过,不行 比如设置权限,开放端口,配置数据库... 最好偶然一个搜索查看可能原因是防火墙端口问题: vim /etc/sysconfig/iptables 在文件中添加下面语句 ...

  3. PHP7兼容mysql_connect的方法

    在php7版本的时候,mysql_connect已经不再被支持了,本文将讲述在代码层面实现php7兼容mysql系列,mysql_connect等操作. PHP7不再兼容mysql系列函数,入mysq ...

  4. Linux系列(34) - yum源文件(1)

    yum源文件各参数含义 在[/etc/yum.repos.d/]目录中,默认有4个yum源文件,其中[CentOS-Linux-BaseOS.repo]是基本yum源文件,如果我们能上网,那它是默认生 ...

  5. spy++查找窗口句柄

    spy++可以用来查找桌面程序(c/s)的窗口句柄,实现自动化测试. def find_idxSubHandle(pHandle, winClass, index=0): ""&q ...

  6. P6378-[PA2010]Riddle【2-SAT】

    正题 题目链接:https://www.luogu.com.cn/problem/P6378 题目大意 给出\(n\)个点\(m\)条边的一张无向图,图中有\(k\)种颜色的点. 要求每种颜色选择一个 ...

  7. ❤️Python接口自动化,一文告诉你连接各大【数据库】建议收藏❤️

    @ 目录 前言 常见数据库 Mysql Oracle sql-server PostgreSQL MongoDB Redis 前言 相信很多小伙伴在使用python进行自动化测试的时候,都会涉及到数据 ...

  8. WPF进阶技巧和实战01-小技巧

    Svg在WPF中的使用 方法1:拷贝svg中的部分代码转换成Geometry(作为Path的Data使用) 在vs或者直接打开svg,看到如下代码: <?xml version="1. ...

  9. mybatis中#{}与${}取值的区别

    1. 首先对于一个接口 Employee getEmpByIdAndName(@Param("id") Integer id,@Param("empName") ...

  10. WPF实现截图(仿微信截图)

    WPF开发者QQ群: 340500857  | 微信群 -> 进入公众号主页 加入组织 每日一笑 肚子疼,去厕所排便,结果什么都没拉出来.看着自己坐在马桶上痛苦又努力却一无所获的样子,仿佛看到了 ...