ACM is a 64-bit integer (_ int64) of C ++)

Source: Internet
Author: User
ACM is a 64-bit integer (_ int64) of C ++)
When I was doing ACM, I often encountered some big integers. The commonly used built-in integer types are often too small: the range of long and Int Is [-2 ^ 31,2 ^ 31), that is,-2147483648 ~ 2147483647. The unsigned range is [0, 2 ^ 32), that is, 0 ~ 4294967295. That is to say, the regular 32-bit integer can only process numbers smaller than 4 billion.
By http://www.acmwiki.com/What should I do if I encounter a number bigger than 4 billion? In this case, the 64-bit extension of C ++ is used. Different compilers have different extensions for 64-bit integers. Based on ACM, the following describes only the extension of vc6.0 and G ++ compiler. The 64-bit Integers of VC are respectively _ int64 and unsigned _ int64. Their ranges are [-2 ^ 63, 2 ^ 63) and [0, 2 ^ 64 ), that is,-9223372036854775808 ~ 9223372036854775807 and 0 ~ 18446744073709551615 (about 180 billion million ). The operation of 64-bit integers is basically the same as that of 32-bit integers, and supports four arithmetic operations and bit operations. When the 64-bit and 32-bit mixed operations are performed, the 32-bit integer is implicitly converted to a 64-bit integer. However, VC input and output are not compatible with _ int64. If you write the following code: 1 _ int64 A; 2 CIN>; 3 cout <A; then, the error c2679: Binary '>' will be received in the 2nd line ': no operator defined which takes a right-hand operand of Type '_ int64' (or there is no acceptable conversion) "error;" error c2593: 'operator' <'is ambiguous "error. Is it impossible to make input and output? Of course not. You can use the C method: scanf ("% i64d", & A); printf ("% i64d", a); to input and output the data correctly. When unsigned _ int64 is used, change "i64d" to "i64u. OJ usually uses the G ++ compiler. The 64-bit extension method is different from that of VC. They are called long and unsigned long respectively. The processing scale is the same as that used except for input and output. For input and output, the extension is better than VC. You can use either 1 long a; 2 CIN> A; 3 cout <A; or scanf ("% LLD", & ); printf ("% LLD", a); when using the unsigned number, change "% LLD" to "% LlU. Finally, let me add: as a special case, if you are using the dev-C ++ g ++ compiler, it uses "% i64d" instead of "% LLD ".

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.