Python solution--Sequence summation of the 2019 Tenth Blue Bridge Cup Final (National Competition)

Introduction: Difficult to remember once, unique decomposition theorem + dfs

topic description

Test question D: Sequence summation
Total score of this question: 10 points
[Problem description]
After learning divisors, Xiao Ming is very curious about divisors. He finds that given a positive integer t, an integer with t divisors can always be found . Xiao Ming is very interested in the smallest number with t divisors, and defines it as St
insert image description here

[Answer Submission]
This is a question to fill in the blanks, you only need to calculate the result and submit it. The result of this question is an integer, only fill in this integer when submitting the answer, filling in redundant content will result in no scoring.

lemma

insert image description here
For example, if the number of factors is 8
, then

8=8 1 The corresponding number is 128 7 times of
2 8=4
2 The corresponding number is 24 2 times 3 times
8=2*4 The corresponding number is 54 2 times 3 times 3
Obviously in this example, 24 is satisfied minimum number of conditions

So first make a prime number table, and then use DFS to traverse it.

python code

prime = []
for i in range(2,1000):
    ok = 1
    for j in range(2,i):
        if i % j == 0:
            ok = 0
            break
    if ok:prime.append(i)
    if len(prime) == 60:
        break
# print(prime)
#存放对应的Si
res = [1]

#求幂
def get(ci, postion):
    t = 1
    for s in range(ci - 1):
        t *= prime[postion]
    return t

def dfs(x, now, j):
    if x == 1:
        return now
    t = 0
    for i in range(2, 61):
        if x % i == 0:
            if t == 0:
                t = dfs(x // i, now * get(i, j), j + 1)
            else:
                t = min(t, dfs(x // i, now * get(i, j), j + 1))
    return t
for x in range(2,61):
    w = dfs(x,1,0)
    res.append(w)
# print(len(res))
# print(res)
print(sum(res))

result

292809912969717649

insert image description here

Guess you like

Origin blog.csdn.net/huadong_xiaolin/article/details/129951731