鱼C论坛

 找回密码
 立即注册
查看: 2316|回复: 1

题目171:寻找各个数位的平方之和也是个平方数的数字

[复制链接]
发表于 2016-9-15 01:07:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Finding numbers for which the sum of the squares of the digits is a square

For a positive integer n, let f(n) be the sum of the squares of the digits (in base 10) of n, e.g.

          f(3) = 32 = 9,
          f(25) = 22 + 52 = 4 + 25 = 29,
          f(442) = 42 + 42 + 22 = 16 + 16 + 4 = 36

Find the last nine digits of the sum of all n, 0 < n < 1020, such that f(n) is a perfect square.


题目:

对正整数 n,定义 f(n) 为它的各个数位的平方之和,例如:


          f(3) = 32 = 9,
          f(25) = 22 + 52 = 4 + 25 = 29,
          f(442) = 42 + 42 + 22 = 16 + 16 + 4 = 36

对于 0 < n < 1020, 中所有满足 f(n) 是完全平方数的 n,求这些 n 之和的最后 9 位数字。

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-9-21 15:16:07 | 显示全部楼层
动态规划题目
from itertools import zip_longest as zip_l, chain, repeat
def do_fast(size = 20, m = 10**9, b = 10):
    S = [0] * (1 + (b-1)**2)
    for d in range(b): S[d * d] = d
    for k in range(1, size):
        loop = [chain(repeat(0, d * d), S) for d in range(b)]
        S = [sum(s) % m for s in zip_l(*loop, fillvalue=0)]
    s = sum([S[j**2] for j in range(int((len(S) - 1)**0.5) + 1)]) % m
    all_ones = 10**size // 9 % m
    return all_ones * s % m
print(do_fast())
142989277
[Finished in 0.2s]
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-7-2 21:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表