Improve algorithm for finding smallest common prime and add table by DOM