这么简洁的题目当然不用数位 DP 啦。
将 (n) 搞成 (10) 的幂次之和计算。枚举后缀长度 (i),考虑它的贡献,因为不能填 (7) 也不用考虑前导零所以就是 (9^i)。
然后乘上 (n-i) 位置上的数字能取到的数量即可。
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int t,p;
ll n,s,k;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
s=0;
k=1;
while(n)
{
p=n%10;
s+=k*(p-(p>6));
n/=10;
k*=9;
}
printf("%lld
",s);
}
return 0;
}