首页 > 其他 > 详细

hdu 2058 The sum problem(数学题)

时间:2015-05-27 21:07:12      阅读:219      评论:0      收藏:0      [点我收藏+]

题意:求[1,n]的子区间,使得子区间的元素和为m

技术分享



代码:

#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)&&(n||m))
    {
        for(int j=(int)sqrt(2*m);j>=1;j--)
        {
            int i=(2*m/j-j+1)/2;
            if((i*2-1+j)*j==2*m&&i+j-1<=n)
            {
                printf("[%d,%d]\n",i,i+j-1);
            }
        }
        printf("\n");
    }
    return 0;
}


hdu 2058 The sum problem(数学题)

原文:http://blog.csdn.net/xky1306102chenhong/article/details/46052071

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!