UVA_10169
This question can obviously pre-process the results and then use them for reference. It is not difficult to calculate the formula. When calculating the number of 0, we use a conversion like X = 10 ^ (log10 (X), so we only need to calculate-log10 (X).
In addition, it should be noted that overflow must be avoided when integer multiplication is involved. If the intermediate result is beyond the int range, it can be forcibly converted to double or long before calculation.
# Include <stdio. h>
# Include <string. h>
# Include <math. h>
# Define MAXD 1000010
Double f [MAXD];
Int d [MAXD];
Void prepare ()
{
Int I, j, k;
Double p1 = 1, p2 = 0;
For (I = 1; I <1000000; I ++)
{
P1 = p1 * (double) I * I + I-1)/(double) I * I + I );
P2 + = log10 (double) I * I + I );
F [I] = 1-p1;
D [I] = (int) (p2-fmod (p2, 1) + 0.5 );
}
}
Int main ()
{
Int n;
Prepare ();
While (scanf ("% d", & n) = 1)
{
If (n = 0)
Printf ("0.000000 0 \ n ");
Else
Printf ("%. 6lf % d \ n", f [n], d [n]);
}
Return 0;
}