Find the leftmost number of n^n and the last side of a number

Source: Internet
Author: User

Problem: Find the leftmost number of n^n and the rightmost one, N (1<=n<=1,000,000,000).

Find the right-hand side:

Analysis: Actually find the left and right side of a number is quite simple, fast power each time only take the result of the last one to participate in the next operation, take the final result of the last

Find the leftmost one:

The n^n can be represented by scientific notation, and the integer part of the valid number represented by the scientific notation is the answer

Enter an N,

Use scientific notation to denote n^n = a * 10^n, where the integral part of a has only one

Both sides take the logarithm at the same time, get N*lg (N) = LG (a) + N

Because 1 < A < 10, so 0 < LG (a) < 1, and n is an integer, that is, LG (a) is a fractional part of N*LG (n), and n is an integer portion of N*LG (n),

So 10^ (N*LG (n)-(int) N*LG (n)) is the result.

Note: The result is larger when you can use __int64 or long long (same)

Find the right number title: http://acm.hdu.edu.cn/showproblem.php?pid=1061

Find the leftmost number topic: http://acm.hdu.edu.cn/showproblem.php?pid=1060

My Code:

Most right:

#include <stdio.h>#include<math.h>#defineLL __int64ll Qfact (ll N) {ll res=1, pow =N;  while(n) {if(N &1) {res*=POW; Res%=Ten; } POW*=POW; Pow%=Ten; N/=2; }    returnRes;}intMain () {intT; scanf ("%d", &t);  while(t--) {LL n, ans; scanf ("%i64d", &N); Ans=qfact (n); printf ("%i64d\n", ans%Ten); }    return 0;}

Leftmost: (Scientific counting method)

#include <stdio.h>#include<math.h>#defineLL __int64intMain () {intT; scanf ("%d", &t);  while(t--) {LL n; scanf ("%i64d", &N); DoubleAns = N*LOG10 (n1.0); Ans= ans-(LL) ans; Ans= POW (10.0, ans); printf ("%i64d\n", (LL) ans); }    return 0;}

    

Find the leftmost single number and the last side of the n^n

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.