Hdoj (HDU) 2139 Calculate The formula (water problem, another problem with JAVAAC)

Source: Internet
Author: User

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
See this time, I confused ...
Sure enough, Java is to hit the table, can not AC, because Java input is a stream, it takes more time than C really much longer ....

Problem Description
You just need to calculate the sum of the formula:1^2+3^2+5^2+......+ n ^2.

Input
In each case, the there is an odd positive integer n.

Output
Print the sum. Make sure the sum would not exceed 2^31-1

Sample Input
3

Sample Output
10

A simple question, it is not translated.
Attach the C language code of AC:

#include <iostream>Const intmax=2345;//Calculate 2345 is just greater than 2^31-1, input output with scanf and printf can not cin and cout otherwise timeout__int64 Db[max];using namespace STD;intMain () {intN,m,i; db[1]=1;//Play Table method     for(i=3; i<=max;i+=2) {db[i]=db[i-2]+i*i; } while(scanf("%d", &n)!=eof) {printf("%i64d\n", Db[n]); }return 0;}

Hdoj (HDU) 2139 Calculate The formula (water problem, another problem with JAVAAC)

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.