optimized calculating of sum of digits squared by using lookup dict