fork download
  1. // File Name : c.cpp
  2. // Development : July 11 2012 21:23:20 IST
  3. // Author : Xeronix
  4.  
  5. #include <iostream>
  6. #include <cstdio>
  7. #include <vector>
  8. #include <math.h>
  9. #include <algorithm>
  10. #include <string>
  11. #include <cstring>
  12. #include <string.h>
  13. #include <cstdlib>
  14. #include <sstream>
  15. #include <stack>
  16. #include <queue>
  17. #include <numeric>
  18. #include <utility>
  19. #include <cctype>
  20. #include <list>
  21. #include <limits.h>
  22. #include <signal.h>
  23. #include <time.h>
  24. #include <map>
  25. #include <set>
  26. #include <float.h>
  27.  
  28. #define TR(c, i) for ( typeof((c).begin()) i = (c).begin(); i != (c).end(); i++ )
  29. #define FOR(i, a, b) for ( i = a; i <= b; i++ )
  30. #define ROF(i, a, b) for ( i = a; i >= b; i-- )
  31. #define ALL(v) (v).begin(), (v).end()
  32. #define SORT(v) sort( ALL(v) )
  33. #define MAX(a, b) ((a) >= (b) ? (a) : (b))
  34. #define MIN(a, b) ((a) <= (b) ? (a) : (b))
  35. #define ABS(a) ((a) < (0) ? (a)*(-1) : (a))
  36. #define SWAP(a, b) {typeof(a) T; T=a; a=b; b=T;}
  37. #define SET(x,a) memset(x,a,sizeof(x))
  38. #define IN(x,a) x.find(a) != x.end()
  39.  
  40. #define SYNC ios_base::sync_with_stdio(false);
  41.  
  42. //#define LIM
  43. #ifdef LIM
  44. int S, D, Y, O;
  45. char *inp, *out, *ipos, *opos, DIG[30];
  46. #define FRMI inp=( char * )malloc( LIM*sizeof( char ) );fread_unlocked( inp,1,LIM,stdin );ipos=inp;
  47. #define FWM out=( char * )malloc( LIM*sizeof( char ) );opos=out;
  48. #define FWO fwrite_unlocked( out,opos-out,1,stdout );
  49. #define GETI(n) n=0;while(*ipos<33){ipos++;}if(*ipos=='-'){S=-1;ipos++;}else{S=1;}while(*ipos>='0'){n=10*n+(*ipos-'0');ipos++;}n*=S;
  50. #define PUTI(n) O=n;D=0;if(O<0){*opos++='-';O*=-1;}if(!O)*opos++='0';else{while(O){Y=O/10;DIG[D++]=O-Y*10+'0';O=Y;}\
  51. while(D--)*opos++=DIG[D];}
  52. #define PUTC(c) *opos++=c;
  53. #endif
  54.  
  55.  
  56. using namespace std;
  57.  
  58. long long int val( int n )
  59. {
  60. long long int v = 9;
  61.  
  62. int i;
  63.  
  64. FOR( i,0,n-2 ) {
  65. v += 9LL*pow( 10,i );
  66. }
  67.  
  68. return v;
  69.  
  70. }
  71.  
  72. long long int calc( long long int n )
  73. {
  74. stringstream ss;
  75. ss << n;
  76. string t = ss.str();
  77. ss.str("");
  78.  
  79. int dig = t.length();
  80.  
  81. if( dig == 1 ) {
  82. return n;
  83. }
  84.  
  85. int i;
  86. string s = "";
  87.  
  88. FOR( i,1,dig-2 ) {
  89. s += t[i];
  90. }
  91.  
  92. long long int fd = t[0] -'0';
  93. long long int ld = n%10;
  94.  
  95. long long int a = dig >= 3 ? val(dig-1) : 9LL;
  96. long long int b = (fd-1)*pow( 10,dig-2 );
  97. long long int c = atoll( s.c_str() ) + (int)(ld>=fd);
  98.  
  99. return a+b+c;
  100. }
  101.  
  102. int main()
  103. {
  104. long long int a, b;
  105.  
  106. cin >> a >> b;
  107.  
  108. cout << calc(b)-calc(a-1) << endl;
  109.  
  110. return 0;
  111. }
Success #stdin #stdout 0.02s 2864KB
stdin
1 10000
stdout
1008