You
are invited to a very simple task: "What is the first digit of the number nn"?
Input. Consists
of several test cases. Each test is located on a separate line and contains one
number n (1 ≤ n ≤ 109).
Output. For
each test case print in a separate line the first digit of desired result.
Sample
input |
Sample
output |
3 4 |
2 2 |
mathematics
The number of digits in number a
equals to . So the number nn
contains len = decimal digits. Consider
the number A = = = . It is obvious that 1 ≤ A < 10. The integer part of
A equals to the first digit of number nn.
Calculate the logarithm of the number A. It equals to ost = nlgn + 1 – len. Then the first digit of the number nn equals to .
Example
Let
n = 4. Then 44 = 256, len = = 3. Number À equals
to = = = 2.56.
Algorithm realization
The
main part of the program.
while(scanf("%lld",&n) == 1)
{
lgg = n * log10((double)n);
The value of len equals to the number of digits in
the number nn.
len = (long long)(lgg + 1e-7) + 1;
ost = lgg + 1 - len;
res = (long long)(pow(10.0,ost) + 1e-7);
printf("%lld\n",res);
}