fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. const int MOD = 1e9+7;
  5. ll power(ll x,int y){
  6. if(y == 0)
  7. return 1;
  8. ll res = 1;
  9. while(y){
  10. if(y&1)
  11. res = (res*x)%MOD;
  12. x = (x*x)%MOD;
  13. y /= 2;
  14. }
  15. return res;
  16. }
  17. int main()
  18. {
  19. ios_base::sync_with_stdio(0);
  20. cin.tie(0);
  21. string s;
  22. cin >> s;
  23. int n = s.length();
  24. ll ans = 0;
  25. for(int i = 0; i < n;++i){
  26. ll digit = s[i] - '0';
  27. ll num_left = i;
  28. ll num_right = n-i-1;
  29. ll left_contribution = (num_left*(num_left+1))/2LL;
  30. left_contribution %= MOD;
  31. left_contribution = (left_contribution * digit)%MOD * power(10LL,n-i-1);
  32. left_contribution %= MOD;
  33. ll right_contribution = (power(10LL,num_right) * (9LL * num_right - 1) + 1) * digit;
  34. right_contribution /= 81LL;
  35. right_contribution %=MOD;
  36. ans = (ans + right_contribution + left_contribution)%MOD;
  37. }
  38. cout << ans << "\n";
  39. }
  40.  
Success #stdin #stdout 0s 4500KB
stdin
100500100500
stdout
650324207