fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int count1=0;
  5. void rec(string S,int b,int i)
  6. {
  7. //cout<<"S="<<S<<endl;
  8.  
  9. string S2 = to_string(b);
  10. if(i == S2.length())
  11. {
  12. if(S != "" && stoi(S) <= b)
  13. {
  14. count1++;
  15. }
  16. return;
  17. }
  18. else
  19. {
  20. if(i == 0)
  21. {
  22. for(int j=0;j<10;j++)
  23. {
  24. if(j ==0 && S=="")
  25. {
  26. rec(S,b,i+1);
  27. }
  28. else
  29. {
  30. string s = S;
  31. s+=(j+'0');
  32. rec(s,b,i+1);
  33. }
  34. }
  35. }
  36. else
  37. {
  38. for(int j=0;j<10;j++)
  39. {
  40. if(S.back() != (j+'0'))
  41. {
  42. if(j ==0 && S=="")
  43. {
  44. rec(S,b,i+1);
  45. }
  46. else
  47. {
  48. string s = S;
  49. s+=(j+'0');
  50. rec(s,b,i+1);
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57.  
  58. int main() {
  59.  
  60. long long a,b;
  61. cin>>a>>b;
  62.  
  63. count1=0;
  64. rec("",b,0);
  65. int countb=count1;
  66.  
  67. count1=0;
  68. rec("",a-1,0);
  69. int counta=count1;
  70.  
  71. cout<<countb-counta<<endl;
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0.01s 5280KB
stdin
1 100
stdout
90