#include #define rep(i,n) for(int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; using P = pair; using vv = vector>; const int INF = (int)1e9; const LL LINF = (LL)1e18; int main(){ int K; cin >> K; vector p(8); rep(i,8) p[i] = i + 1; int ans = 0; do{ string s; rep(i,8) s.push_back('0' + p[i]); int N = stoi(s); if(N % K == 0) ans++; }while(next_permutation(p.begin(), p.end())); cout << ans << endl; return 0; }