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.

Sample Input

20 10
50 30
0 0

Sample Output

[1,4]
[10,10] [4,8]
[6,9]
[9,11]
[30,30] // 遍历所有子列
 #include<stdio.h>
int main()
{
int n, m, i,j, t, flag;
while(scanf("%d %d", &n, &m), !(n==&&m==))
{
for(i=;i<=n;i++)
{
flag=; t=;
for(j=i;j<=n;j++)
{
t+=j;
if(t==m)
{ flag=; break; }
if(t>m) break;
}
if(flag) printf("[%d,%d]\n", i, j);
}
printf("\n");
}
return ;
}

Time Limit Exceeded

// 老老实实算吧
 #include<stdio.h>
#include<math.h>
int main()
{
int n, m, i,j;
while(scanf("%d %d", &n, &m), !(n==&&m==))
{
for(i=(int)sqrt(2.0*m);i>;i--) // a1*n+n*(n-1)/2=(2*a1+(n-1))*n/2=m,
{ // 又a1>=1, 则n<sqrt(2*m).
j=(*m/i-i+)/; // a1=(2*m/n-n+1)/2
if((*j+i-)*i/==m)
printf("[%d,%d]\n", j, i+j-);
}
printf("\n");
}
return ;
}

AC

 

7E - The sum problem的更多相关文章

  1. summary of k Sum problem and solutions in leetcode

    I found summary of k Sum problem and solutions in leetcode on the Internet. http://www.sigmainfy.com ...

  2. Subset sum problem

    https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...

  3. HDu 1001 Sum Problem 分类: ACM 2015-06-19 23:38 12人阅读 评论(0) 收藏

    Sum Problem Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  4. HD2058The sum problem

    The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  5. Maxmum subsequence sum problem

    We have a lot of ways to solve the maximum subsequence sum problem, but different ways take differen ...

  6. HDU 2058 The sum problem(枚举)

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

  7. NYOJ--927--dfs--The partial sum problem

    /* Name: NYOJ--927--The partial sum problem Author: shen_渊 Date: 15/04/17 19:41 Description: DFS,和 N ...

  8. 动态规划法(三)子集和问题(Subset sum problem)

      继续讲故事~~   上次讲到我们的主人公丁丁,用神奇的动态规划法解决了杂货店老板的两个找零钱问题,得到了老板的肯定.之后,他就决心去大城市闯荡了,看一看外面更大的世界.   这天,丁丁刚回到家,他 ...

  9. HDU 2058:The sum problem(数学)

    The sum problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. 团队第十次 # scrum meeting

    github 本此会议项目由PM召开,召开时间为4-15日晚上9点,以大家在群里讨论为主 召开时长10分钟 任务表格 袁勤 负责整理实验报告前后端交互,即xml文件传值部分 负责整理实验报告前后端交互 ...

  2. HTML基础篇

    由于一些原因,要换工作了,毫无准备,心情郁闷了几天.但是还是更新了简历,准备复习面试.面 了3天.面试中问到了一些问题,想好好整理一下.越是大公司越看重基础.这几天遇到的面试题,有15到简答题,有两页 ...

  3. 通过日志来看Spring跨库更新操作的事务

    场景介绍: 一个项目俩个数据源,连接俩个不同的库 数据源初始化 @Configuration @MapperScan(basePackages = "com.qing.mapper.paym ...

  4. maven 版本发布添加上时间戳

    使用插件添加时间戳 我使用的是spring boot - 2.0.3.RELEASE版本 pom中加入 <!-- 加入这个 就可以直接在配置文件中取到时间戳了,注意: 由于${}方式会被mave ...

  5. SQL SERVER 死锁

    sp_lock 查看锁表名称 select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableNamefr ...

  6. python之路:列表及元组之定义

      python开发之路:列表及元组之定义 列表是以后用处较大的一个数据类型,这种数据类型可以存储按组分类的信息.好了,我不多说,开始讲了! 好了,现在我有个情景,我要存东汉时期(韩国,秦国,……)所 ...

  7. .net Cache 需要注意的地方

    CacheItemPolicy policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(ti ...

  8. git 之连接tfs的git服务器

    tfs中的git的管理,注意区分是主页地址,还是代码地址,代码地址中会有   _git http://ip:8080/tfs/p/elasticsearch6.2.0 http://ip:8080/t ...

  9. django-rest-framework配置json web token

    安装jwt库,简单快速的生成我们所需要的token 1.安装djangorestframe pip install djangorestframe 2.在settings.py的INSTALLED_A ...

  10. 爬虫之进阶 基于twisted实现自制简易scrapy框架(便于对scrapy源码的理解)

    1.调度器 class Scheduler(object): """调度器""" def __init__(self, engine): & ...