Problem:
Score : 500 points

Problem Statement

Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.

Constraints

1 \leq N < 10^{100}

1 \leq K \leq 3

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the count.

Sample Input 1

100
1

Sample Output 1

19

The following 19 integers satisfy the condition:

1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100

Sample Input 2

25
2

Sample Output 2

14

The following 14 integers satisfy the condition:

11,12,13,14,15,16,17,18,19,21,22,23,24,25

Sample Input 3

314159
2

Sample Output 3

937

Sample Input 4

9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3

Sample Output 4

117879300

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//int atoi(const char *str)

int ruijo(int i,int j){
  int mat=1;
  for(int k=0;k<j;k++){
    mat*=i;}
  return mat;
}

int c(int l,int k){
  int mat=1;
  int tmp=l;
  for(int i=0;i<k;i++){
    mat*=tmp;
    tmp--;}
  for(int i=0;i<k;i++){
    mat/=i+1;}
  return mat;
}

int myatoi(char n){
  if(n=='0') return 0;
  if(n=='1') return 1;
  if(n=='2') return 2;
  if(n=='3') return 3;
  if(n=='4') return 4;
  if(n=='5') return 5;
  if(n=='6') return 6;
  if(n=='7') return 7;
  if(n=='8') return 8;
  if(n=='9') return 9;
  return 0;}

long int sum(char n[],int k){
  if(k<=0) return 1;
  int len=strlen(n);
  long int res=0;
  if(len>k) res+=c(len-1,k)*ruijo(9,k);
  res+=(myatoi(n[0])-1)*c(len-1,k-1)*ruijo(9,k-1);
  //res+=c(len-2,k-1)*ruijo(9,k-1);
  res+=sum(n+1,k-1);
  return res;
}

int main(){
  char n[102];
  int k;
  scanf("%s",n);
  scanf("%d",&k);


  long int res=sum(n,k);

  printf("%ld\n",res);
  
  return 0;
}