Pabon_SEC

Simple Addition

Jun 10th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int arr[]= {0,1,3,6,10,15,21,28,36,45};
  6.  
  7. long long func(long long n)
  8. {
  9.     long long sum = 0;
  10.  
  11.     while(n)
  12.     {
  13.         sum += (n/10)*45 + arr[n%10];
  14.  
  15.         n/=10;
  16.     }
  17.  
  18.     return sum;
  19. }
  20.  
  21. int main()
  22. {
  23.     long long n,m,i;
  24.  
  25.     while(scanf("%lld%lld",&n,&m)==2)
  26.     {
  27.         if(n<0 && m<0)
  28.             break;
  29.  
  30.         printf("%lld\n",func(m)-func(n-1));
  31.     }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment