#include using namespace std; int main(void){ vector p = {1,2,3,4,5,6,7,8}; int K; int ans = 0; cin >> K; do { int N = 0; for( int i = 0; i < 8; i++ ) N += pow(10,i)*p[i]; if( N%K == 0 ) ans++; }while(next_permutation(p.begin(),p.end())); cout << ans << endl; }