The method is very simple. The statistics are quite painful... WA wants to vomit... it's just a reference to other people's code...
Note that the first digit of the current number is 49 ....
Program:
[Cpp]
# Include <iostream>
# Include <cmath>
# Include <stack>
# Include <queue>
# Include <set>
# Include <algorithm>
# Include <stdio. h>
# Include <string. h>
# Define ll unsigned long
# Define OOS 1000000007
Using namespace std;
Ll dp [23] [3];
Void pre ()
{
Int I, j, k;
Memset (dp, 0, sizeof (dp ));
Dp [0] [0] = 1;
For (I = 1; I <= 22; I ++)
{
Dp [I] [0] = dp [I-1] [0] * 10-dp [I-1] [1]; // Number of numbers with the maximum length of I and not including 49
Dp [I] [1] = dp [I-1] [0]; // Number of numbers with a maximum length of 9 and No 49
Dp [I] [2] = 10 * dp [I-1] [2] + dp [I-1] [1]; // Number of I contained 49
}
Return;
}
Ll getans (ll n)
{
Ll p, ans, l, s [22];
Bool f = false;
L = 0;
S [0] = 0;
While (n)
{
S [++ l] = n % 10;
N/= 10;
}
Ans = 0;
For (p = l; p> = 1; p --)
{
Ans + = dp [P-1] [2] * s [p];
If (f)
Ans + = dp [P-1] [0] * s [p];
Else
If (s [p]> 4) ans + = dp [P-1] [1];
If (s [p + 1] = 4 & s [p] = 9) f = true;
}
Return ans;
}
Int main ()
{
Int T;
Ll n;
Scanf ("% d", & T );
Pre ();
While (T --)
{
Cin> n;
N ++;
Cout <getans (n) <endl;
}
Return 0;
}
# Include <iostream>
# Include <cmath>
# Include <stack>
# Include <queue>
# Include <set>
# Include <algorithm>
# Include <stdio. h>
# Include <string. h>
# Define ll unsigned long
# Define OOS 1000000007
Using namespace std;
Ll dp [23] [3];
Void pre ()
{
Int I, j, k;
Memset (dp, 0, sizeof (dp ));
Dp [0] [0] = 1;
For (I = 1; I <= 22; I ++)
{
Dp [I] [0] = dp [I-1] [0] * 10-dp [I-1] [1]; // Number of numbers with the maximum length of I and not including 49
Dp [I] [1] = dp [I-1] [0]; // Number of numbers with a maximum length of 9 and No 49
Dp [I] [2] = 10 * dp [I-1] [2] + dp [I-1] [1]; // Number of I contained 49
}
Return;
}
Ll getans (ll n)
{
Ll p, ans, l, s [22];
Bool f = false;
L = 0;
S [0] = 0;
While (n)
{
S [++ l] = n % 10;
N/= 10;
}
Ans = 0;
For (p = l; p> = 1; p --)
{
Ans + = dp [P-1] [2] * s [p];
If (f)
Ans + = dp [P-1] [0] * s [p];
Else
If (s [p]> 4) ans + = dp [P-1] [1];
If (s [p + 1] = 4 & s [p] = 9) f = true;
}
Return ans;
}
Int main ()
{
Int T;
Ll n;
Scanf ("% d", & T );
Pre ();
While (T --)
{
Cin> n;
N ++;
Cout <getans (n) <endl;
}
Return 0;
}