HDU 1060 Leftmost Digit

Source: Internet
Author: User

Basic ideas: (Refer to the great God and add their own thinking)

Considering that this problem needs to enter so large number A, and also to find a AA, to find out will be larger, more bits. At that time, consider using the large number method (array implementation), the result is not possible. Look at the online great god using the logarithmic method, cleverly avoid dealing with such a large number. This is the charm of mathematics!!

If aa=b, both sides take logarithm alog10a=log10b at the same time, thus have b=10alog10a. Now we focus on 10ALOG10A, first example: A number 2310, this number, replaced by 10c power, where the c=3. xxxxx. If rounding him up must be 3,103 is the maximum weight, then the remainder of the 100.xxxxx is the base of the highest position to be asked.

#include <iostream>#include<cmath>using namespacestd;intMain () {intN; CIN>>N; __int64 d,b;//int Type No    DoubleA,c;  while(n--) {unsignedLongm; CIN>>m; A=M*LOG10 (m*1.0);//alog10ab= (__int64) A;//take the wholeC=a-b;//0.xxxxxd= (__int64) POW (10.0, c);//10^0.xxxxx Roundingcout<<d<<Endl; }    return 0;}

__int64:

64 is an integer type of data that has no definite specification. In today's mainstream compilers, support for the 64 integer is also standard and varies in form. In general, 64-bit integers are defined in long long and __int64 two (VC also supports _int64), while output to standard output is printf ("%lld", a), printf ("%i64d", a), and cout << A three different ways.

There are a few more:

    1. A long long definition can be used for gcc/g++, not platform-limited, but not for VC6.0.
    2. __int64 is the definition of the WIN32 platform compiler 64-bit long integer and cannot be used with Linux.
    3. "%lld" is used for the Linux i386 platform compiler, and "%i64d" is used for WIN32 platform compilers.
    4. Cout can only be used for C + + compilation, in VC6.0, the cout does not support 64-bit long integers.

For details, see: https://www.byvoid.com/blog/c-int64/

HDU 1060 Leftmost Digit

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.