sicily 1218. 纪念邮票

http://soj.sysu.edu.cn/show_problem.php?pid=1218

之前大概做了下居然做对了。。然后化简了下。。只要注意长度为偶数时左边L的值要+1

#include <cstdio>
#include <cmath>
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int len = sqrt(2*m)+1;
    while(--len)
    {
        int l = m/len-len/2+!(len&1);
        int r = m/len+len/2;
        if(l < 1 || r > n) continue;
        if((l+r)*(r-l+1)/2 == m)
            printf("[%d,%d]\n",l,r);
    }
}                                 

你可能感兴趣的:(sicily)