package main import . "fmt" var k,ans int var f[9]bool func count(d int, s string) { if d==0 { Sscan(s,&d) if d%k==0 { ans++ } return } for i:=1;i<=8;i++ { if f[i] { continue } f[i]=true count(d-1,Sprint(s,i)) f[i]=false } } func main() { Scan(&k) count(8,"") Println(ans) }