#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

int n;
bool can[10];

void read()
{
	cin >> n;
	
	string t;
	cin >> t;

	for(char c: t)
		can[c - '0'] = 1;
}

int64_t d[10][30][20][10][10];

int64_t rec(int i, int c2, int c3, int c5, int c7)
{
	if(c2 < 0) return 0;
	if(c3 < 0) return 0;
	if(c5 < 0) return 0;
	if(c7 < 0) return 0;
	if(i == n)
		return c2 + c3 + c5 + c7 == 0;

	int64_t &memo = d[i][c2][c3][c5][c7];
	if(memo != -1)
		return memo;

	memo = 0;
	for(int d = 1; d < 10; d++)
		if(can[d])	
		{
			int n2 = c2, n3 = c3, n5 = c5, n7 = c7;

			int x = d;
			while(x % 2 == 0) n2--, x /= 2;
			while(x % 3 == 0) n3--, x /= 3;
			while(x % 5 == 0) n5--, x /= 5;
			while(x % 7 == 0) n7--, x /= 7;

			memo += rec(i + 1, n2, n3, n5, n7);
		}

	return memo;
}

int64_t sq(int64_t x) { return x * x; }

void solve()
{
	int64_t answer = 0;
	if(can[0])
	{
		int64_t numb1 = 1, rem = 1;
		int cnt_av = 0;
		for(int i = 1; i < 10; i++)
			if(can[i]) cnt_av++;

		for(int i = 0; i < n; i++)
		{
			numb1 *= (cnt_av + 1);
			rem *= cnt_av;
		}

		answer += (numb1 - rem) * (numb1 - rem); 
	}

	memset(d, -1, sizeof(d));
	for(int c2 = 0; c2 < 30; c2++)
		for(int c3 = 0; c3 < 20; c3++)
			for(int c5 = 0; c5 < 10; c5++)
				for(int c7 = 0; c7 < 10; c7++)
					answer += sq(rec(0, c2, c3, c5, c7));

	cout << answer << endl;
}

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

	read();
	solve();
	return 0;
}

