Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}

ll nCr(int n, int r) {
  ll ans = 1;
  for (int i = n; i > n - r; --i) {
        ans = ans*i;
  }
  for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
  }
  return ans;
}


//-------------------------------------------------
//




//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s ;
  int k ;
  int a ;
  cin >> s >> k ;
  ll ans = 0 ;
  
  if(k==2){
    if(n<10){
      cout << 0 <<endl ;
      return 0 ;
    }
  }
  if(k==3){
    if(n<100){
      cout << 0 <<endl ;
      return 0 ;
    }
  }
      
  
  if(k==1){
    a = 9 ;
  }
  else if(k==2){
    a = 9*9 ;
  }
  else if(k==3){
    a = 9*9*9 ;
  }
  
  int b ;
  
  if(k==1){
    b = s.at(0) - '0' ;
  }
  else if(k==2){
    b = (s.at(0)-'0')*10 + s.at(1) -'0' ;
  }
  
  else if(k==3){
    b = (s.at(0)-'0')*100 + (s.at(1) -'0')*10 + s.at(2)-'0' ;
  }
  
  int c ;
  
  if(k==1){
    c = 1 ;
  }
  else if(k==2){
    c = 10 ;
  }
  else if(k==3){
    c = 100 ;
  }
  
  int n = SZ(s) ;
  int m = n-1 ;
  
  ans += max((ll)0,nCr(m,k)*a) ;
  
  if(k==1){
    FOR(i,c,b+1){
      ans++ ;
    }
  }
  
  else if(k==2){
    FOR(i,c,b+1){
      if(i==10 || i==20 || i==30 || i==40 || i==50 || i==60 || i==70 || i==80 || i==90 ){
        ans += 9*(n-2) ;
      }
      else{
        ans++ ;
      }
    }
  }
  
  else if(k==3){
    FOR(i,c,b+1){
      if(i==100 || i==200 || i==300 || i==400 || i==500 || i==600 || i==700 || i==800 || i==900 ){
        ans += 81*nCr(n-3,2) ;
      }
      else if(i==101 ||i==102 ||i==103 ||i==104 ||i==105 ||i==106 ||i==107 ||i==108 ||i==109 ||i==201 ||i==202 ||i==203 ||i==204 ||i==205 ||i==206 ||i==207 ||i==208 ||i==209 ||i==301 ||i==302 ||i==303 ||i==304 ||i==305 ||i==306 ||i==307 ||i==308 ||i==309 ||i==401 ||i==402 ||i==403 ||i==404 ||i==405 ||i==406 ||i==407 ||i==408 ||i==409 ||i==501 ||i==502 ||i==503 ||i==504 ||i==505 ||i==506 ||i==507 ||i==508 ||i==509 ||i==601 ||i==602 ||i==603 ||i==604 ||i==605 ||i==606 ||i==607 ||i==608 ||i==609 ||i==701 ||i==702 ||i==703 ||i==704 ||i==705 ||i==706 ||i==707 ||i==708 ||i==709 ||i==801 ||i==802 ||i==803 ||i==804 ||i==805 ||i==806 ||i==807 ||i==808 ||i==809 ||i==901 ||i==902 ||i==903 ||i==904 ||i==905 ||i==906 ||i==907 ||i==908 ||i==909 || i==110 ||i==120 ||i==130 ||i==140 ||i==150 ||i==160 ||i==170 ||i==180 ||i==190 ||i==210 ||i==220 ||i==230 ||i==240 ||i==250 ||i==260 ||i==270 ||i==280 ||i==290 ||i==310 ||i==320 ||i==330 ||i==340 ||i==350 ||i==360 ||i==370 ||i==380 ||i==390 ||i==410 ||i==420 ||i==430 ||i==440 ||i==450 ||i==460 ||i==470 ||i==480 ||i==490 ||i==510 ||i==520 ||i==530 ||i==540 ||i==550 ||i==560 ||i==570 ||i==580 ||i==590 ||i==610 ||i==620 ||i==630 ||i==640 ||i==650 ||i==660 ||i==670 ||i==680 ||i==690 ||i==710 ||i==720 ||i==730 ||i==740 ||i==750 ||i==760 ||i==770 ||i==780 ||i==790 ||i==810 ||i==820 ||i==830 ||i==840 ||i==850 ||i==860 ||i==870 ||i==880 ||i==890 ||i==910 ||i==920 ||i==930 ||i==940 ||i==950 ||i==960 ||i==970 ||i==980 ||i==990){
        ans += 9*(n-3) ;
      }
      else{
        ans++ ;
      }
    }
  }
  
  
  cout << ans <<endl ;
  return 0 ;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:71:8: error: 'n' was not declared in this scope
   71 |     if(n<10){
      |        ^
a.cc:77:8: error: 'n' was not declared in this scope
   77 |     if(n<100){
      |        ^