[HDU] [1060] Leftmost Digit

Problem Description

Loading...

Problem Analysis

A problem Yu Shen mentioned before
Take the logarithm and you can work it out
x=nlogn
10 to the power of x is n to the power of n
So the fractional part of x is the string of decimals in scientific notation
So truncating it gives the leading digit

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include<stdio.h>
#include<math.h>
int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		double n;
		scanf("%lf",&n);
		n*=log10(n);
		n-=(__int64)n;
		printf("%d\n",(int)pow(10.0,n));
	}
	return 0;
}

Problem record: 【杭电】[1060]Leftmost Digit

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...