#include using namespace std; template inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef long long int ll; #define EPS (1e-7) #define INF (1 << 30) #define LLINF (1LL << 60) #define PI (acos(-1)) #define MOD (1000000007) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------- vector divisor(ll n) { vector ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; auto yakusu = divisor(k); ll m = yakusu.size(); set st; for (ll i = 1; i < (m / 2); i++) { ll ac = yakusu[i]; ll bd = yakusu[m - i - 1]; for (ll j = 1; j < ac; j++) { for (ll k = 1; k < bd; k++) { vector rec = {to_string(j), to_string(ac - j), to_string(k), to_string(bd - k)}; bool flg = false; for (auto tmp : rec) { if (stoll(tmp) > n) { flg = true; } } if (flg) { continue; } st.insert(rec[0] + rec[1] + rec[2] + rec[3]); st.insert(rec[1] + rec[0] + rec[2] + rec[3]); st.insert(rec[0] + rec[1] + rec[3] + rec[2]); st.insert(rec[1] + rec[0] + rec[3] + rec[2]); } } } // for (auto tmp : st) // { // cout << tmp << endl; // } cout << (ll)st.size() * 2LL << endl; }