64-bit integer (_ int64 and long) in C/C ++)

Source: Internet
Author: User

When I was doing ACM, I often encountered some big integers. The commonly used built-in integer types are often too small: Long and int
The value range 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.
What should we do if we encounter a number larger than 4 billion? In this case, the 64-bit extension of C ++ is used. Different compilers have different extensions for 64-bit integers. The ACM-based requirements are described below.
Vc6.0 and G ++ compiler extensions.
The 64-bit Integers of VC are respectively _ int64 and unsigned _ int64. Their ranges are [-2 ^ 63,
2 ^ 63) and [9223372036854775808 ^ 64), that is ~ 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 64-bit and
During a 32-bit hybrid operation, a 32-bit integer is implicitly converted to a 64-bit integer. However, the compatibility between VC input and output and _ int64 is not very good. If you write the following code:
1 _ int64;
2 CIN>;
3 cout <;

Then, the error c2679: Binary '>': No operator will be received in the 2nd line.
Defined which takes a right-hand operand of Type '_ int64' (or there is
No acceptable conversion) "error;" error c2593: 'operator <'will be received on the 3rd line'
Is ambiguous "error. Cout and CIN can't do anything about _ int64, which is complicated to write, but often
No.
Is it impossible to make input and output? Of course not. You can use C:
Scanf ("% i64d", & );
Printf ("% i64d", );
The input and output are correct. 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.
Long. 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
1 long;
2 CIN>;
3 cout <;
You can also use
Scanf ("% LLD", & );
Printf ("% LLD", );

Change "% LLD" to "% LlU" when using the unsigned number.

 

Http://hi.baidu.com/fandywang_jlu/blog/item/7c8e98cc0db2081601e928a1.html

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.