#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pld> vpld;
typedef unordered_map<int, int> mpii;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	cout << fixed;
	cout.precision(17);

	ll k; cin >> k;
	cin.ignore();
	string s; getline(cin, s);
	string t; getline(cin, t);

	vl vec(10, k);
	unordered_map<int, int> S, T;
	for (const auto &a : s) S[a - '0']++, vec[a - '0']--;
	for (const auto &a : t) T[a - '0']++, vec[a - '0']--;

	auto calc = [](auto &cnt) {
		ll ret = 0;
		for (int i = 1; i <= 9; i++) ret += i * powl(10, cnt[i]);
		return ret;
	};

	ll ans = 0;
	for (int i = 1; i <= 10; i++) {
		if (!vec[i]) continue;
		--vec[i];
		for (int j = 1; j <= 10; j++) {
			if (!vec[j]) continue;
			S[i]++;
			T[j]++;
			if (calc(S) > calc(T)) { //ok win
				if (i == j) ans += vec[i] * (vec[i] + 1);
				else ans += (vec[i] + 1) * vec[j];
				//cout << i << " " << j << "\n";
			}
			S[i]--;
			T[j]--;
		}
		++vec[i];
	}

	ld cnt = 9 * k - 8;
	cout << ans / (cnt * (cnt - 1));
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  ll n;
  cin >> n;
  set<ll> s;

  for(ll a=2 ; a*a <= n; ++a){
    ll x = a*a;
    while(x <= n){ 
      s.insert(x);
      x *= a;
    }   
  }
  ll ans = n-s.size();
  cout << ans << endl;
  return 0;
}
