#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

unsigned long long conv(int base,const string& fact){
  unsigned long long res = 0;
  unsigned long long digit = 1ULL;
  for(int i = fact.size() - 1; i >= 0; i--){
    if('A' <= fact[i] && fact[i] <= 'Z'){
      res += (fact[i] - 'A' + 10) * digit;
      digit *= base;
    }
    else{
      res += (fact[i] - '0') * digit;
      digit *= base;
    }
  }
  return res;
}

int main(){
  int base;
  string fact;
  while(cin >> base >> fact){
    if(base == 0 && fact == "0") break;
    unsigned long long init = conv(base,fact);
    unsigned long long prime_factor[37] = {};
    for(int i = 2; i <= base; i++){
      while(base % i == 0){
        prime_factor[i]++;
        base /= i;
      }
    }

    unsigned long long res = numeric_limits<unsigned long long>::max();
    for(unsigned long long i = 2; i <= 36; i++){
      if(prime_factor[i] == 0) continue;
      unsigned long long count = 0;
      unsigned long long tmp = init;

      while(tmp > 0){
        count += tmp / i;
        tmp /= i;
      }
      res = min(res,count / prime_factor[i]);
    }

    if(res == numeric_limits<unsigned long long>::max()) res = 0;    
    cout << res << endl;
  }
}
### Prompt

Your task is to create a CPP solution to the following problem:

You are one of ICPC participants and in charge of developing a library for multiprecision numbers and radix conversion. You have just finished writing the code, so next you have to test if it works correctly. You decided to write a simple, well-known factorial function for this purpose:

<image>

Your task is to write a program that shows the number of trailing zeros when you compute M! in base N, given N and M.



Input

The input contains multiple data sets. Each data set is described by one line in the format below:


N M


where N is a decimal number between 8 and 36 inclusive, and M is given in the string repre- sentation in base N. Exactly one white space character appears between them.

The string representation of M contains up to 12 characters in base N. In case N is greater than 10, capital letters A, B, C, ... may appear in the string representation, and they represent 10, 11, 12, ..., respectively.

The input is terminated by a line containing two zeros. You should not process this line.

Output

For each data set, output a line containing a decimal integer, which is equal to the number of trailing zeros in the string representation of M! in base N.

Example

Input

10 500
16 A
0 0


Output

124
2

### Response

```cpp
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

unsigned long long conv(int base,const string& fact){
  unsigned long long res = 0;
  unsigned long long digit = 1ULL;
  for(int i = fact.size() - 1; i >= 0; i--){
    if('A' <= fact[i] && fact[i] <= 'Z'){
      res += (fact[i] - 'A' + 10) * digit;
      digit *= base;
    }
    else{
      res += (fact[i] - '0') * digit;
      digit *= base;
    }
  }
  return res;
}

int main(){
  int base;
  string fact;
  while(cin >> base >> fact){
    if(base == 0 && fact == "0") break;
    unsigned long long init = conv(base,fact);
    unsigned long long prime_factor[37] = {};
    for(int i = 2; i <= base; i++){
      while(base % i == 0){
        prime_factor[i]++;
        base /= i;
      }
    }

    unsigned long long res = numeric_limits<unsigned long long>::max();
    for(unsigned long long i = 2; i <= 36; i++){
      if(prime_factor[i] == 0) continue;
      unsigned long long count = 0;
      unsigned long long tmp = init;

      while(tmp > 0){
        count += tmp / i;
        tmp /= i;
      }
      res = min(res,count / prime_factor[i]);
    }

    if(res == numeric_limits<unsigned long long>::max()) res = 0;    
    cout << res << endl;
  }
}
```