尤拉計畫問題三matlab實現

2021-08-28 17:00:26 字數 489 閱讀 6612

the prime factors of 13195 are 3,7,13 and 29. 

what is the largest prime factor of  the number 600851475143?

採用迴圈來遍歷求最大質數因子。設定乙個迴圈從2到比自身小1,逐次相除迭代(計算機最擅長的事就是做迴圈了),若除完之後的數只能被自身及一整除,那麼該數就是最大質數因子。

t = 600851475143;

for i = 2:t-1

if mod(t,i) == 0 %i是t的質數因子

t = t / i; %%如果t只能被自身及一整除

if t == 1

a = i; %i就是t的最大質數因子

break

endend

enda

盡量每天更新一題,希望大家多多交流學習!

尤拉計畫問題七matlab實現

by listing the first six prime numbers 2,3,5,7,11,and 13,we can see that the 6th prime is 13.what is the 10001st prime number?我們首先列舉出一些有用的條件 好的,以上的條件讓...

尤拉計畫問題九matlab實現

a pythagorean triplet is a set of three natural numbers,a for example,there exists exactly one pythagorean triplet for which a b c 1000.find the produ...

尤拉計畫問題十matlab實現

the sum of the primes below 10 is 2 3 5 7 17.find the sum of all the primes below two million.在前面的尤拉計畫問題七中我們已經對素數的概念有了乙個理性的認識,眾所周知,matlab是乙個功能很強大的軟體,裡...