求一个数的首位:1561351516565465165=a.b * 10^c log10(a.b * 10^c)=log10(a.b) + log10(10^c)=log10(a.b) + c=x a.b < 10 log10(a.b) < 1 10^(x-c) = a.b a就是首位
#include<cstdio>
#include<cmath>
int main()
{
long long n;
scanf(
"%lld",&n);
double x =
log10(n);
int c = (
int)x;
double a_b =
pow(
10,x-c);
printf(
"%d\n",(
int)a_b);
return 0;
}
pow()函数:
头文件:
#include < math.h>
pow() 函数用来求 x 的 y 次幂(次方),其原型为:
double pow(
double x,
double y);
pow()用来计算以x 为底的 y 次方值,然后将结果返回。