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. C6.cpp

    可以将 一个array对象赋给另一个对象 对于下标值出现负数的情况下可以解释为在头指针的位置处向前移动对应的字节 可以使用vector.at(n_elem)来获取元素等价于vector[n_elem] ...

  2. springboot学习五:IDEA外部tomcat发布

    pom.xml配置 屏蔽自带tomcat <dependency> <groupId>org.springframework.boot</groupId> < ...

  3. 【机器学习_9】sklearn

    背景 机器学习的重头戏就在sklearn,里面包含各种机器学习算法.希望尽量通过便易上手的方式掌握这个库. 资料 官网--随时查 https://scikit-learn.org/stable/ sk ...

  4. 关于全局变量,static,define和const

        其实按照现在主流的观点,应该尽量少用全局变量和define,尽量多用临时变量,并且用const替换值define,用短小精悍的函数替换函数define.     对这些我倒是也没有什么意见,只 ...

  5. (6.1)linux操作系统基础

    Linux介绍: Linux是一种自由和开放源码的操作系统,存在着许多不同的Linux版本,但它们都使用了Linux内核.Linux可安装在各种计算机硬件设备中,比如手机.平板电脑.路由器.台式计算机 ...

  6. python xlrd xlwt

    1.什么是xlrd模块? 2.为什么使用xlrd模块? 3.怎样使用xlrd模块? 1.什么是xlrd模块? ♦python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel, ...

  7. redis hashmap数据结构分析

    说明一点:redis的hash中每一个key都是一个单独的hash表,field是hash表中的key,value是hash表中的value: //redis中hash数据结构为:key-field- ...

  8. leetcode966

    class Solution(object): def spellchecker(self, wordlist: 'List[str]', queries: 'List[str]') -> 'L ...

  9. nodejs 实现文件拷贝

    通过4中不通的方式实现对一个文件的拷贝 方式一:readFile 异步一次性读取文件再写入 //异步形式读取文件 function copyFile(url){ const extName = pat ...

  10. 侧脸生成正脸概论与精析(一)Global and Local Perception GAN

    侧脸生成正脸我一直很感兴趣,老早就想把这块理一理的.今天来给大家分享一篇去年的老文章,如果有不对的地方,请斧正. Beyond Face Rotation: Global and Local Perc ...