1074. 第一位数字

n^n=10^(x)×a,a的整数部分就是首位数字。则两边同时取10的对数，nlgn=x+lga，剩下的就是算了。

#include <stdio.h>
#include <math.h>
int main()
{
int n;
scanf("%d",&n);
while(n)
{
double a, x;
a=n*log10(n);
a-=(int)a;
x=pow(10, a);
printf("%d\n",(int)x);
scanf("%d",&n);
}
return 0;
}


%成耀dalao

n^n = t×10^a，a为整数，t∈(0,10)

lgt取值范围为(0,1)

t = 10^(nlgn - a) = 10^(nlgn - [nlgn])

[em:15]

import math
while True:
n = int(input())
if(n == 0):
break
cha = n*math.log10(n) - int(n*math.log10(n))
t = pow(10,cha)
print(int(t))


include

using namespace std;
int main()
{
int n;
while(scanf(“%d”,&n)==1&&n)
{
double tem=n*log10(n);
tem-=(int)tem;
int ans=pow(10,tem);
cout<<ans<<endl;
}
}

[em:01]啧啧啧

include

using namespace std;

int main()
{
int n;
double a,b,c;

while(cin >> n && n != 0)
{
a = n*log10(n);
b = modf(a,&c); // modf函数可以分离小数
b = modf(pow((double)10,b),&c);
cout << c << endl;
}


}

include

int del(inta,int n,intlen)
{
int j,k=0,b[500];
for(j=0;j<
len;j++)
{b[j]=a[j];
a[j]=(a[j]n+k)%10;
k=(a[j]
n+k)/10;
}
if(k!=0)a[j++]=k;
*len=j;
return a;
}
void solve(unsigned int n)
{
int len=1,i,a[500];
a[0]=n;
for(i=2;i<=n;i++)
del(a,n,&len);
printf(“%d”,a[len-1]);
}
int main()
{
unsigned int n;
while(1)
{
scanf(“%u”,&n);
if(n==0)break;
else if(n==1)printf(“1\n”);
else solve(n);
}
return 0;
}

#include <cmath>
#include <iostream>
int main() {
for (int n; std::cin >> n, n;) {
double helper;
std::cout << (int)floor(pow(10, modf(n * log10(n), &helper))) << '\n';
}
}