determined function that generates A006255 in polynomial time