#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) v.begin(), v.end()
template<class T>bool chmax(T& a, const T& b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T& a, const T& b) { if (b<a) { a=b; return 1;} return 0;}

ll mul(ll x, ll a) {
    ll ret = 1;
    rep(i, a) ret *= x;
    return ret;
}

int main() {
    string X;
    ll M;
    cin >> X >> M;


    if (X.size() == 1) {
        ll x = stoll(X);
        if (x <= M) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }

    ll len = X.size();
    ll ma = 0;
    for (int i = 0; i < X.size(); ++i) {
        chmax(ma, (ll)(X[i] - '0'));
    }

    for (ll i = ma+1; i < 2e18; ++i) {
        if (i > 100) i += 1e12;
        ll tmp = 0;
        double judge = 0;
        for (int j = 0; j < len; ++j) {
            tmp += mul(i, (len - j - 1)) * (X[j] - '0');
            judge += pow(i, (len - j - 1)) * (X[j] - '0');
        }

        if (judge > 2e18 || tmp > M) {
            for (ll k = max(ma+1, i - (ll)1e12-1); k < 2e18; k++) {
                if (k > 100) k += 1e6;
                ll tm = 0;
                double ju = 0;
                for (int l = 0; l < len; ++l) {
                    tm += mul(k, (len - l - 1)) * (X[l] - '0');
                    ju += pow(k, (len - l - 1)) * (X[l] - '0');
                }

                if (ju > 2e18 || tm > M) {
                    for (ll m = max(ma+1, k - (ll)1e6-1); m < 2e18; ++m) {
                        ll t = 0;
                        double j = 0;
                        for (int n = 0; n < len; ++n) {
                            t += mul(m, (len - n - 1)) * (X[n] - '0');
                            j += pow(m, (len - n - 1)) * (X[n] - '0');
                        }

                        if (j > 2e18 || t > M) {
                            cout << m - (ma+1) << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
}
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
    long k;
    string s, t;
    long double co[10] = {}, co1[10] = {}, co2[10] = {};
    long double ans = 0, ans1 = 0;
    cin >> k >> s >> t;
    long double kd = k;
    for (int i = 0; i < 4; i++) {
        co[int(s[i] - '0')]++;
        co1[int(s[i] - '0')]++;
        co[int(t[i] - '0')]++;
        co2[int(t[i] - '0')]++;
    }
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i == j && co[i] < k - 1) {
                co1[i]++, co2[j]++;
                long s1 = 0, t1 = 0;
                for (int k1 = 1; k1 < 10; k1++) {
                    long s2 = 1, t2 = 1;
                    for (int l = 0; l < co1[k1]; l++) {
                        s2 *= 10;
                    }
                    for (int l = 0; l < co2[k1]; l++) {
                        t2 *= 10;
                    }
                    s1 += k1 * s2, t1 += k1 * t2;
                }
                if (s1 > t1) {
                    ans += (kd - co[i]) * (kd - co[i] - 1);
                }
                co1[i]--, co2[j]--;
            }
            else if (i != j && co[i] < k && co[j] < k) {
                co1[i]++, co2[j]++;
                long s1 = 0, t1 = 0;
                for (int k1 = 1; k1 < 10; k1++) {
                    long s2 = 1, t2 = 1;
                    for (int l = 0; l < co1[k1]; l++) {
                        s2 *= 10;
                    }
                    for (int l = 0; l < co2[k1]; l++) {
                        t2 *= 10;
                    }
                    s1 += k1 * s2, t1 += k1 * t2;
                }
                if (s1 > t1) {
                    ans += (kd - co[i]) * (kd - co[j]);
                }
                co1[i]--, co2[j]--;
            }
        }
    }
    ans1 = (9 * kd - 8) * (9 * kd - 9);
    cout << fixed << setprecision(16) << ans / ans1 << endl;
}