T^T(2)
Description
T ^ T This is much like a cry of expression is not it! In fact, it is the power of friends ~ T-T.
When T is relatively large when T ^ T will be very large, and now this number if you find a total of how many bits on it.
Input
Input comprises a plurality of sets of test data, the test data is only one number for each T (0 <T <2 ^ {31}) T (0 <T <2 (31)).
Output
Please output T ^ T is a total number of digits.
Sample Input 1
3
5
Sample Output 1
2
4
Problem-solving ideas
A thought:
Brute force.
Direct calculation of n n-th power, and then converted to a string, then the count
, of course, this method certainly bother
Thinking two:
Because we did a quick question of power. Stupid I wanted to try
the following code:
#include<stdio.h>
#include<math.h>
long long int f(int a,int b)
{
int r=1;
while(b!=0)
{
if(b%2==1)
{
r*=a;
}
a*=a;
b>>=1;
}
return r;
}
int main()
{
int n;
long long int f(int a,int b);
while(scanf("%d",&n)!=EOF)
{
printf("%.0f\n",floor(log10(f(n,n)))+1);
}
return 0;
}
The results do not guess ah! time out!
So, I am such a waste of time
to continue to observe. You see this log function, it is not there-something? ? ?
log (a ^ b) = b
* log (a) remember him! very useful!
ok
Thinking three:
such. Have a problem. The extra log is doing it
seek digits. log10 = 1; log100 = 2
then the number of bits required number n can be
n * log (n) +1
code is as follows:
#include<stdio.h>
#include<math.h>
int main()
{
long long int n,m;
while(scanf("%lld",&n)!=EOF)
{
m=floor(n*log10(n))+1;
printf("%lld\n",m);
}
return 0;
}
Weeping, Method two rows so many really grueling.