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. VS2015创建类库项目后添加不了WPF资源字典,窗口,用户控件处理办法

    打开项目工程文件在PropertyGroup标签最后加上下面3行: <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FA ...

  2. TopSnackbar,在顶部滑出显示的Snackbar;

    TopSnackbar 既然你能找到这篇文章,说明你一定使用过或了解Snackbar,所以我就不介绍Snackbar了.嗯~有图有真相! 嗯,就是图上这样: 我把Snackbar的源码拉了过来,重写了 ...

  3. Python多线程实例

    前言 感觉理解python多线程用“切换”和“共享”就差不多了.这里就贴上一个抢车票的小小实例,还有自己在编程过程中遇到的坑..... 实例:抢车票 抢车票有三类人:会员.弄了加速包.普通人. 说说区 ...

  4. H3路由器映射端口到外网

    登录华三路由器 依次点击菜单 “防火墙”-->“NAT”-->“内部服务器”  将看到一个内部服务器转换的列表页面 点击列表页面的的新建然后完善页面提交即可 如下操作:

  5. MPI 集合通信函数 MPI_Reduce(),MPI_Allreduce(),MPI_Bcast(),MPI_Scatter(),MPI_Gather(),MPI_Allgather(),MPI_Scan(),MPI_Reduce_Scatter()

    ▶ 八个常用的集合通信函数 ▶ 规约函数 MPI_Reduce(),将通信子内各进程的同一个变量参与规约计算,并向指定的进程输出计算结果 ● 函数原型 MPI_METHOD MPI_Reduce( _ ...

  6. linux命令--xargs的使用

    xargs 是给命令传递参数的一个过滤器,也是组合多个命令的一个工具. xargs 可以将管道或标准输入(stdin)数据转换成命令行参数,也能够从文件的输出中读取数据. xargs 也可以将单行或多 ...

  7. VS编写一个项目的路径规划

    原文路径:http://blog.csdn.net/puttytree/article/details/7838419 https://www.cnblogs.com/zhehan54/p/45678 ...

  8. springmvc 学习

    第一章回顾JavaWeb中的MVC设计模式 1)MVC这种设计模式,不光运用于Web领域,而且也能用于非Web领域 2)今天说的MVC特指一种表现层设计模式,不限于Java语言 第二章回顾struts ...

  9. OO第十五次作业

    一.测试与正确性论证的效果差异 测试和正确性论证分别是从理论和实践两个角度去规范程序的正确性的,我认为其主要的区别在于对于程序透明度的需求上, 测试作为一种实践手段,他的实施的要求是比较低的:在完全了 ...

  10. Delphi中Chrome Chromium、Cef3学习笔记(五)

    原文   http://blog.csdn.net/xtfnpgy/article/details/48489489   一.模拟移动鼠标 //  SetCursorPos(StrToInt(Edit ...