compute n from lattice dimension