10th National Championship java test E: sequence sum

Test Question E: Sequence Sum


[Problem description] After
learning about divisors, Xiao Ming was very curious about divisors. He found that given a positive integer t, an integer
containing t divisors can always be found. Xiao Ming is very interested in the smallest number containing t divisors and
defines it as S t.
For example, S 1 = 1, S 2 = 2, S 3 = 4, S 4 = 6,...
Now Xiao Ming wants to know, what is the sum of the first 60 Si? That is, what is S 1 + S 2 + ··· + S 60?
Idea:
There is still a big gap between this and asking what is the divisor of S100, because when the divisor is a prime number, their numbers are relatively large. I searched the Internet for the knowledge of number theory for decomposing prime factors, and they said if When the divisor is a prime number, if the smallest number is required, then the prime number of 2 minus one power. For example, S13, then its minimum number is 2**12.
We can see that if s is not a prime number, then our solution is how to multiply it to equal the divisor. We say that the exponent of the decomposition factor of a number minus one is in the sum Their multiplication is a divisor of that number. All we can reversely deduct as:

s12=  2*2*3  =   3*2*2   =  3*4  =  4*3  
2**(3-1)*3**(2-1)*5**(2-1)=60  约数求对应的数。
我们先把12的分解因数表示 一个数的分解质数的指数
如:60 2**2*3*5 这是一个数的分解质数  我们求60的约数就是 指数加一相乘   (2+1)*(1+1)*(1+1)=12
所以我们就知道可以用约数来求那个最小数,我们可以先把约数的分解因数全部求出来然后在算出最小数就可以算出对应的最小数了。

      

Answer: 292809912969717649
program:

def z(a):  #判断质数
    if a==2 or a==3:
        return 1
    if a%2==0  or a==1:
        return 0
    k=1
    while k*k<=a:
        k+=2
        if a%k==0:
            return 0
    return 1
b=[]
for p in range(2,1000):
    if z(p):
        b.append(p)
m=[0 for i in range(61)]
def san(a,a1):
    global k
    if  z(a) or a==1:
        a1+=str(a)+" "
        p=0
        k1=a1.split(" ")
        k1.pop()
        d=1 
        for i  in k1:
            d*=b[p]**(int(i)-1)
            p+=1
        if k==1:
            k=d
        k=min(k,d)
        return k
    for i in range(2,60):
        if i>a:
            break
        if a%i==0:
            san(a//i,a1+ str(i)+" ")

for i in range(1,60+1):
    k=1
    san(i,"")
    m[i]=k

print(sum(m))

Reprinting is prohibited. Only for self-study. No responsibility for program errors.

Guess you like

Origin blog.csdn.net/weixin_46640345/article/details/112981360