예제 #1
0
void FindContinuousSequence(int n)
{
	if(n < 3) return;
	int small = 1;
	int big = 2;
	int middle = (1 + n) / 2;
	int sum = small + big;

	while(small < middle)
	{
		if(sum == n)
		{
			PrintContinuousSequence(small, big);
		}

		while(sum > n)
		{
			sum -= small;
			small++;
			if(sum == n)
			{
				PrintContinuousSequence(small, big);
			}
		}

		big++;
		sum += big;
	}
}
void FindContinuousSequence(int sum)
{
    if(sum < 3) return;
    int small = 1; 
    int big = 2;
    int middle = (1 + sum) / 2;
    int curSum = small + big;

    while(small < middle) {
        if(curSum == sum)
            PrintContinuousSequence(small, big);

        while(curSum > sum && small < middle) {
            curSum -= small;
            small ++;
            if(curSum == sum)
                PrintContinuousSequence(small, big);
        }
        big ++;
        curSum += big;
    }
}