尤拉計劃問題三matlab實現
Problem3: Largest prime factor
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 end end end a
儘量每天更新一題,希望大家多多交流學習!
相關推薦
尤拉計劃問題三matlab實現
Problem3: Largest prime factor The prime factors of 13195 are 3,7,13 and 29. What is the largest prime factor of the number 60085
尤拉計劃問題二matlab實現
Problem 2:Even Fibonacci numbers Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2
尤拉計劃問題一matlab實現
Problem 1:Multiples of 3 and 5 if we list all the natural numbers blew 10 that multiples of 3 or 5, we get 3,5, 6 and 9,The sum of those multiples i
尤拉計劃問題六matlab實現
Problem 6:Sum square difference The sum of the squares of the first ten natural numbers is:  
尤拉計劃問題五matlab實現
Problem 5 : Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. Wha
尤拉計劃問題四matlab實現
Problem4: Largest palindrome product A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numb
尤拉計劃問題十matlab實現
Problem 10 :Summation of primes The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. 思路 : 在
尤拉計劃問題九matlab實現
Problem 9 : Special Pythagorean triplet(特殊的畢達哥拉斯三重奏) A Pythagorean triplet is a set of three natural numbers, a < b < 
尤拉計劃問題八matlab實現
problem 8 :Largest product in a series The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 583
尤拉計劃問題七matlab實現
Problem 7 : 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實現
Problem 14 :Longest Collatz sequence The following iterative sequence is defined for the set of positive integers:  
尤拉計劃問題十三matlab實現
Problem 13 :Large sum Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339021027987979982208375902
尤拉計劃問題十二matlab實現
Problem 12 : The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be &nbs
尤拉計劃問題十一matlab實現
Problem 11 :Largest product in a grid In the 20×20 grid below, four numbers along a diagonal line have been marked in red. &n
尤拉計劃問題十五matlab實現
Problem 15 :Lattice paths Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 rout
尤拉計劃問題十七matlab實現
Problem 17 :Number letter counts If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 +
尤拉計劃問題二十的matlab實現
Problem 20 : Factorial digit sum n! means n × (n − 1) × ... × 3 × 2 × 1 For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the s
尤拉計劃第四題:關於求迴文數。第五題,第六題,第七題,第八題,第九題,第十題
第四題:迴文數問題 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 9
模式識別三--MATLAB實現貝葉斯分類器
貝葉斯分類器的分類原理是通過某物件的先驗概率,利用貝葉斯公式計算出其後驗概率,即該物件屬於某一類的概率,選擇具有最大後驗概率的類作為該物件所屬的類。也就是說,貝葉斯分類器是最小錯誤率意義上的優化,它遵循“多數佔優”這一基本原則。 一、分類器的基本概念 經過了一個階段的模式識別學習,對於模式和模式類的概念有一
尤拉計劃 第四十七題
The first two consecutive numbers to have two distinct prime factors are:14 = 2 × 715 = 3 × 5The first three consecutive numbers to have t