fork download
  1. #include<stdio.h>
  2. #include<algorithm>
  3. #include<iostream>
  4. using namespace std;
  5. long long b,i,x,v,c,ans,anc;
  6. int j,k,a[20];
  7. main(){
  8.  
  9. // freopen("a.in","r",stdin);
  10. // freopen("a.out","w",stdout);
  11.  
  12. cin>>b;
  13. k=0; x=1; j=0;
  14. while(b!=0) {a[k]=b%10; b/=10; k++;} for (i=1; i<k; i++) x*=10; if (k==0) x=0; //cout<<x<<" ";
  15. k--;
  16. while(x!=0) {
  17. v=45*(x/10)*k;
  18. c=(a[k]*(a[k]-1)/2)*x+v*a[k]+a[k];
  19. ans+=j*a[k]*x+c; j+=a[k];
  20. x/=10; k--;
  21.  
  22. } //cout<<ans<<" ";
  23. ans-=j;
  24.  
  25. cin>>b;
  26. k=0; x=1; j=0;
  27. while(b!=0) {a[k]=b%10; b/=10; k++;} for (i=1; i<k; i++) x*=10; //cout<<x;
  28. k--;
  29. while(x!=0) {
  30. v=45*(x/10)*k; //cout<<"v=="<<v<<" ";
  31. c=(a[k]*(a[k]-1)/2)*x+v*a[k]+a[k]; //cout<<"c=="<<c<<" ";
  32. anc+=j*a[k]*x+c; j+=a[k]; //cout<<"anc=="<<anc<<" ";
  33. x/=10; k--; //cout<<endl;
  34.  
  35. }
  36.  
  37.  
  38.  
  39. cout<<anc-ans;
  40.  
  41. }
Success #stdin #stdout 0s 5396KB
stdin
9999999999999
9999999999999
stdout
117