题意
分析
这道题明显是一道数位dp+矩阵乘法优化的题目。
易得答案为
(∑x)2−∑x22,x∈SN
.
我们用 Cnti 表示数位和为i的个数。
用 sumi 表示数位和为i的数的和。
用 sqri 表示数位和为i的数的平方和。
则可得:
递推公式
cnti=∑j=19cnti−j
sumi=∑j=1910∗sumi−j+j∗cnti−j
sqri=∑j=19100∗sqri−j+20∗j∗sumi−j+j2∗cnti−j
参考程序
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define maxn 35
#define ll long long
#define mo 1000003
using namespace std;
struct note{
ll a[maxn][maxn];
}a;
ll n,pq;
ll mul_num(ll x,ll y){
ll ret=1;
while (y) {
if (y % 2==1) ret=ret*x % mo;
y/=2;
x=x*x % mo;
}
return ret;
}
note mul(note x,note y) {
note ret;
memset(ret.a,0,sizeof(ret.a));
fo(i,1,30)
fo(j,1,30)
fo(k,1,30)
ret.a[i][j]=(ret.a[i][j]+x.a[i][k]*y.a[k][j]) % mo;
return ret;
}
note pow(note x,ll y){
note ret;
bool bz=0;
while (y) {
if (y % 2==1) {
if (!bz) bz=1,ret=x;
else ret=mul(ret,x);
}
x=mul(x,x);
y/=2;
}
return ret;
}
int sqr(ll x){return x*x % mo;}
int main(){
pq=mul_num(2,mo-2);
scanf("%lld",&n);
fo(i,1,24)
a.a[i+3][i]=1;
a.a[28][28]=a.a[29][29]=1;
fo(i,1,9) {
/// sqr
a.a[i*3-2][25]=a.a[i*3-2][28]=100;
a.a[i*3-1][25]=a.a[i*3-1][28]=20*(10-i);
a.a[i*3][25]=a.a[i*3][28]=sqr(10-i);
// sig
a.a[i*3-1][26]=a.a[i*3-1][29]=10;
a.a[i*3][26]=a.a[i*3][29]=(10-i);
/// num
a.a[i*3][27]=1;
}
a=pow(a,n);
ll ans=sqr(a.a[27][29])-a.a[27][28]+mo;
ans=(ans % mo)*pq % mo;
printf("%lld",ans);
return 0;
}