Cannot think of anything else to optimize. What I have done:
for each n calculates all prime p and its corresponding m{p} such that p^{m{p}} is no larger than n. Multiply all these prime powers together (take modulo 10 first)
For each multiplication, check a precalculated remainder map (map[i][j] stores the remainder for ith prime of power with remainder j)
Cannot think of anything else to optimize. What I have done: for each n calculates all prime p and its corresponding m{p} such that p^{m{p}} is no larger than n. Multiply all these prime powers together (take modulo 10 first) For each multiplication, check a precalculated remainder map (map[i][j] stores the remainder for ith prime of power with remainder j)