HDU 1060 leftmost Digit (math log)

Source: Internet
Author: User
Tags math log

Test instructions: Given a number n, lets you find the nth number of N of the first digit.

Analysis: A look at this n fast to int limit, it is obvious can not do directly, to transform a bit. Since this is an index, we can take down the index.

That is, to take the logarithm, set ans = n ^ n, on both sides take 10 as the base logarithm of lg (ANS) = n * LG (10), and then this integer part is 10 multiple parties,

No use, that is to say we want the small number of parts, and then take the index, OK. Also note to use a long long because it may be super int, for the first time forget, WA.

The code is as follows:

#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <queue > #include <cstring> #include <cmath>using namespace Std;typedef long long ll;int main () {    int n, T;  Cin >> T;    while (t--) {        cin >> N;        Double ans = n * log10 (n);        Ans-= (ll) ans;//decimal part        cout << (LL) Pow (ten, ans) << Endl;    }    return 0;}

HDU 1060 leftmost Digit (math log)

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.