提交时间:2023-08-14 12:35:22
运行 ID: 98227
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; long long a[MAXN]; long long f(long long x) { long long sum = 0; while (x) { sum += x % 10; x /= 10; } return sum; } int main() { int n; cin >> n; long long maxx = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; maxx = max(maxx, a[i]); } if (n <= 5000) { long long sum = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { long long x = a[i] + a[j]; sum += f(x); } } cout << sum; } else { long long sum1 = 0, ans = 0; for (int i = 0; i < n; ++i) { sum1 += f(a[i]); } for (int i = 0; i < n; ++i) { ans += n * f(a[i]) + sum1; } cout << ans; } return 0; }