Sum of squares and cubes and

Source: Internet
Author: User
Problem description gives a continuous integer and calculates the sum of squares of all even numbers and the sum of all odd numbers. The input data contains multiple groups of test instances. Each group of test instances contains a row consisting of two integers, M and N. Output for each group of input data, the output line should contain two integers x and y, indicating the sum of the squares of all the even numbers in the continuous integer of the segment and the sum of all the odd numbers of cubes and.
You can think that a 32-bit integer is enough to save the result. Sample input1 32 5 sample output4 2820 152 code:

# Include <stdio. h>
Int main ()
{
Int m, n, I, T;
While (scanf ("% d", & M, & N )! = EOF)
{
Int S1 = 0, S2 = 0;
If (M> N) // note that m <N;
{T = m; M = N; n = T ;}
For (I = m; I <= N; I ++)
{
If (I % 2 = 0)
S 1 = S1 + I * I;
If (I % 2! = 0)
S2 = S2 + I * I;
}
Printf ("% d \ n", S1, S2 );
}
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.