提交时间:2023-08-14 12:20:49

运行 ID: 98126

#include<bits/stdc++.h> #define int long long using namespace std; const int N = 2e5+2; int n,ans,a[N]; bool chk = 0; int calc(int x) { int ans = 0; for(;x;) { ans += (x%10); x /= 10; } return ans; } bool cmp() { int ansa = 0,ansb = 0; for(int i = 1;i <= n;i++) for(int j = 1;j <= n;j++) ansa += calc(a[i]+a[j]); for(int i = 1;i <= n;i++) ansb += 2*n*calc(a[i]); if(ansa == ansb) printf("ok\n"); else printf("no %d %d\n",ansa,ansb); } signed main() { scanf("%lld",&n); for(int i = 1;i <= n;i++) scanf("%lld",&a[i]); // if(chk) cmp(); if(n <= 5000) { for(int i = 1;i <= n;i++) for(int j = 1;j <= n;j++) ans += calc(a[i]+a[j]); } else { for(int i = 1;i <= n;i++) ans += 2*n*calc(a[i]); } printf("%lld",ans); return 0; }