hdu 2058 The sum problem(数学题)】的更多相关文章

解题报告:可以说是一个纯数学题,要用到二元一次和二元二次解方程,我们假设[a,b]这个区间的所有的数的和是N,由此,我们可以得到以下公式: (b-a+1)*(a+b) / 2 = N;很显然,这是一个二元一次方程,如果可以解出这个方程里的a,b就可以了,N是已知的,那么可以怎么一个公式怎么解二元方程呢?这里有两种方法可以选择,第一种是可以枚举a = 1,2,3.....,一直枚举到N/2,a是不可能大于N/2,这个你可以自己证明一下,但是这样做的缺点就是数据量还是太大了,N/2任然达到了10的八…
The sum problem 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 <=…
一个数学问题:copy了别人的博客 #include<cstdio> #include<cstdlib> #include<cmath> int main() { int n,m,i,j; while(~scanf("%d%d",&n,&m)) { for( j=(int)sqrt(2*m); j>=1;j--) { i= (2*m/j-j+1)/2; if((i*2-1+j)*j == 2*m && i+j-1…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2058 问题描述 给定一个序列1,2,3,...... N,你的工作是计算所有可能的子序列,其子序列的总和为M. 输入 输入包含多个测试用例. 每个情况包含两个整数N,M(1 <= N,M <= 1000000000).输入以N = M = 0结束. 输出  对于每个测试用例,打印其总和为M的所有可能的子序列.格式显示在下面的示例中.在每个测试用例后打印一个空行. 示例输入 20 10 50 30…
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 <= 1000000…
传送门 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).i…
题目: 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. 思路: 刚开始做写了一个尺取法,脑抽的一批.(这几天心情真的是颓的很,连带脑瓜也不好用了,抓紧调整~~~~) 其实可以根据等差数列求和公式求出这个子序列的长度的一个大致的范围为k=sqrt(2*m),然后根据m和k求出首项a1,然后将a1…
题意:给定一个N和M,N表示从1到N的连续序列,让你求在1到N这个序列中连续子序列的和为M的子序列区间. 析:很明显最直接的方法就是暴力,可是不幸的是,由于N,M太大了,肯定会TLE的.所以我们就想能不能优化一下,找一个范围.想到这是一个连续的序列而且是从1开始的,这不就是一个等差数列么,公差是1罢了.由求和公式得Sn = (a1+an) * n / 2;所以说n最大就是sqrt(M*2)(想一想为什么),因为a1+an 一定是大于n的.如果我们取区间的和,那么Sn = (ai+aj) * (j…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4961 Problem Description Number theory is interesting, while this problem is boring. Here is the problem. Given an integer sequence a1, a2, -, an, let S(i) = {j|1<=j<i, and aj is a multiple of ai}. If S…
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).i…