歐拉計劃-第3,6題

中文網:https://pe-cn.github.io/
原網址:https://projecteuler.net/
算法弱雞。Hahaha。

前兩天出去玩了,今天多寫兩個好了。
3.
在這裏插入圖片描述

ans = []
n = 600851475143
iter_max = int(n ** 0.5)
for num in range(2,iter_max):
    if n%num == 0:
        ans.append(num)
        n/=num
        while n%num == 0:
            n/=num
print(ans)

最終答案:
[71, 839, 1471, 6857]
取6857
在這裏插入圖片描述
You are the 468525th person to have solved this problem…

在這裏插入圖片描述

s1 = 0 
k1 = 0
for num in range(101):
    s1 += num
    k1 += num**2
s1 **= 2
s1-k1

numpy寫的話,比較節約。

a = np.linspace(1,100,100)
k = np.sum(a)**2 - np.sum(a*a)

25164150

在這裏插入圖片描述
425385了。

5.這次是1-20的最小公倍數
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章