The sum of continuous natural numbers (Multiple Solutions)

Source: Internet
Author: User
/**/ /*
For a given natural number M, find all consecutive natural number segments (continuous number greater than 1). The sum of all the numbers in these consecutive natural number segments is M.
Example: 1998 + 1999 + 2000 + 2001 + 2002 = 10000, so a natural number segment from 1998 to 2002 is a solution of M = 10000.

 


Input Format
A single row containing an integer returns the value of M (10 <= m <= 2,000,000)
 


Output Format
Each line has two natural numbers. The first and last numbers in a continuous natural number segment that meet the conditions are given. The two numbers are separated by a space, the first of all output rows is listed in ascending order from small to large. For a given input data, there must be at least one solution.
 

*/
# Include < Stdio. h >

Int Main ( Void )
... {
Long I, J, K, M;

Scanf ( " % LD " , & M );
K = M / 2 + 1 ;
For (I = 1 ; I <= K; I ++ )
For (J = I + 1 ; J <= M; j ++ )
If (J - I + 1 ) * (I + J) / 2   > = M)
... {
If (J - I + 1 ) * (I + J) / 2   = M)
... {
Printf ("% LD", I, j );
}
Break ;

}


System ( " Pause " );
Return   0 ;
}

/**/ //////////////////////////////////////// /////////

# Include < Stdio. h >

Int Main ()
... {
Register Long I, n, T, f, g;
Scanf ( " % LD " , & N );
For (I = N; I > 1 ; I -- )
... {
If (F = N < 1 )) % I = 0   && (T = F / I + 1 - I )) % 2 = 0   && (G = T > 1 ) > 0 )
Printf ( " % LD " , G, G + I - 1 );

}
 
Return   0 ;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.