欧拉计划 发表于 2016-9-15 01:07:08

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

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 位数字。

jerryxjr1220 发表于 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 = * (1 + (b-1)**2)
    for d in range(b): S = d
    for k in range(1, size):
      loop =
      S =
    s = sum( 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
页: [1]
查看完整版本: 题目171:寻找各个数位的平方之和也是个平方数的数字