https://codeforc.es/contest/1195/problem/D1
给\(n\)个等长的十进制数串,定义操作\(f(x,y)\)的结果是“从\(y\)的末尾开始一个一个交替放得到的数”,求\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}f(a_i,a_j)\)
很明显每个第\(k\)位(从1开始)都会恰好在\(2k\)和\(2k-1\)位各贡献\(n\)次。预处理出\(pow10\)然后暴力就可以了。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
const ll mod=998244353;
ll ans;
ll calc(ll x){
ll res=0;
ll base=1;
while(x){
ll r=x%10ll;
res=(res+base*11ll%mod*r%mod)%mod;
x/=10;
base=(base*100ll)%mod;
}
//cout<<res<<endl;
return res%mod;
}
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
int n;
while(~scanf("%d", &n)) {
for(int i=1;i<=n;++i){
scanf("%lld",&a[i]);
}
ans=0;
for(int i=1;i<=n;i++){
ans=(ans+calc(a[i]))%mod;
}
printf("%lld\n",ans*n%mod);
}
}