#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void integerFactorization(int n, vector<int>& base, vector<int>& expo)
{
    base.clear();
    expo.clear();
    int a = 2;
    while(a * a <= n){
        int b = 0;
        while(n % a == 0){
            ++ b;
            n /= a;
        }
        if(b > 0){
            base.push_back(a);
            expo.push_back(b);
        }
        ++ a;
    }
    if(n > 1 || base.size() == 0){
        base.push_back(n);
        expo.push_back(1);
    }
}

long long toInt(string s, int n)
{
    long long ret = 0;
    for(unsigned i=0; i<s.size(); ++i){
        ret *= n;
        if(isdigit(s[i]))
            ret += s[i] - '0';
        else
            ret += s[i] - 'A' + 10;
    }
    return ret;
}

int main()
{
    for(;;){
        int n;
        string s;
        cin >> n >> s;
        if(n == 0)
            return 0;

        vector<int> base, expo;
        integerFactorization(n, base, expo);

        long long m = toInt(s, n);

        long long ret = LLONG_MAX;
        for(unsigned i=0; i<base.size(); ++i){
            long long m2 = m;
            long long tmp = 0;
            while(m2 > 0){
                tmp += m2 / base[i];
                m2 /= base[i];
            }
            ret = min(ret, tmp / expo[i]);
        }

        cout << ret << endl;
    }
}
### Prompt

Please formulate 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
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void integerFactorization(int n, vector<int>& base, vector<int>& expo)
{
    base.clear();
    expo.clear();
    int a = 2;
    while(a * a <= n){
        int b = 0;
        while(n % a == 0){
            ++ b;
            n /= a;
        }
        if(b > 0){
            base.push_back(a);
            expo.push_back(b);
        }
        ++ a;
    }
    if(n > 1 || base.size() == 0){
        base.push_back(n);
        expo.push_back(1);
    }
}

long long toInt(string s, int n)
{
    long long ret = 0;
    for(unsigned i=0; i<s.size(); ++i){
        ret *= n;
        if(isdigit(s[i]))
            ret += s[i] - '0';
        else
            ret += s[i] - 'A' + 10;
    }
    return ret;
}

int main()
{
    for(;;){
        int n;
        string s;
        cin >> n >> s;
        if(n == 0)
            return 0;

        vector<int> base, expo;
        integerFactorization(n, base, expo);

        long long m = toInt(s, n);

        long long ret = LLONG_MAX;
        for(unsigned i=0; i<base.size(); ++i){
            long long m2 = m;
            long long tmp = 0;
            while(m2 > 0){
                tmp += m2 / base[i];
                m2 /= base[i];
            }
            ret = min(ret, tmp / expo[i]);
        }

        cout << ret << endl;
    }
}
```