尤拉計畫問題九matlab實現

2021-08-28 21:34:27 字數 544 閱讀 2360

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 product abc.

這題的話思路很簡單,用for迴圈去實現,定義三個迴圈變數a,b,c,若滿足以下條件:

就把滿足條件的三個數相乘,乘積賦值給s,最後s就是輸出結果。

tic

for a = 1:1000

for b = 1:1000

for c = 1:1000

if a^(2) + b^(2) == c^(2) && a + b + c == 1000

s = a*b*c;

%%disp(a),disp(b),disp(c);

disp(s)

endend

endendtoc

尤拉計畫問題三matlab實現

the prime factors of 13195 are 3,7,13 and 29.what is the largest prime factor of the number 600851475143?採用迴圈來遍歷求最大質數因子。設定乙個迴圈從2到比自身小1,逐次相除迭代 計算機最擅長的事...

尤拉計畫問題七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實現

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