fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define endl '\n'
  5. ll N = 1e9+7;
  6. ll oo =1e13;
  7. const ll maxx = 1000000 + 3;
  8. ll n,k,q,x,y,z,l,r,mid,ans;
  9.  
  10.  
  11. void go(ll num , set<ll>v) {
  12. if (num > n)return;
  13. ans++;
  14. for (ll j =0;j<10;j++) {
  15. set<ll>nv=v;
  16. nv.insert(j);
  17. if (nv.size()>2) {
  18. continue;
  19. }
  20. go(num*10+j,nv);
  21.  
  22. }
  23. }
  24. void solve() {
  25. cin>>n;
  26. for (ll i =1 ;i <10;i++) {
  27. set<ll>v;
  28.  
  29. v.insert(i);
  30. go(i,v);
  31.  
  32. }
  33. cout<<ans<<endl;
  34. }
  35. int main() {
  36. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  37. ll t=1 ;
  38. // cin >>t;
  39. while (t--) {
  40. ans=0;
  41. solve();
  42. }
  43. }
Success #stdin #stdout 0s 5320KB
stdin
123
stdout
113