Advertisement
makispaiktis

Project Euler 3 - Largest even factor in Matlab

Apr 11th, 2020 (edited)
1,143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.35 KB | None | 0 0
  1. % The prime factors of 13195 are 5, 7, 13 and 29.
  2. % What is the largest prime factor of the number 600851475143 ?
  3.  
  4. clear all
  5. clc
  6.  
  7. N = 13195
  8. % Create a vector, that will contain all the factors, first is number 1
  9. f(1) = 1;
  10. for i = 3:N/2
  11.     if mod(N, i) == 0 && isprime(i)
  12.         f(length(f)+1) = i;
  13.     end
  14. end
  15. % f;
  16. solution = f(length(f))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement