HDU1001 for implicit type conversion of the accumulate formula, hdu1001 accumulate Formula

Source: Internet
Author: User

HDU1001 for implicit type conversion of the accumulate formula, hdu1001 accumulate Formula

HDU 1001 is stuck.

Inspired by Xiao Bai, such cycle problems are directly converted into formulas for solving to optimize the time. But! I just can't go through it!

Problem code:

# Include <stdio. h> int main () {int a; while (scanf ("% d", & )! = EOF) printf ("% d \ n", a * (1 + a)/2); return 0 ;}

The problem is that although the question indicates that the final result will be within 32 bits, there is no guarantee that a * (1 + a) is also 32bit ....... cainiao ignores the implicit type conversion before Division, resulting in the result being 0 when the data size is appropriate .......

This is over .......

# Include <stdio. h> int main () {long a; while (scanf ("% lld", & )! = EOF) printf ("% lld \ n", a * (1 + a)/2); return 0 ;}

 

Related Article

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.