not urgent, but if you see this and have time please help me, thank you , Please help , LAST prime under n
Show older comments
I need to write a code which the instruction is below, I tried all I could, but I don't know how to store the last element and find the prime factors of the next number, please read, your help will change my grade dramatically, I appreciate so much if you help, this is due tomorrow and I just found out about this website, if you see this and know about matlab please help.
Calculate the largest prime numbers below 5000, 10000, and 100000. Calculate the largest prime factor of the next integer above your prime. Your answer will be six numbers. Three primes, and three largest prime factors of the next integer. You may use the isprime and factor commands, but you will lose points for using the primes command in your submission (though you may check your work with it). Example: Calculate the largest prime below 10. This number is 7, which you may obtain by whatever method you prefer (trial division is easy to understand and loops well). The next integer above this prime number is 8. The largest prime factor of 8 is 2. Thus, the answers for a limit of 10 are: 7 as the prime, 2 as the largest prime factor of the next number
what I have so far:
n=1000000;
i=1:n;
isprime=true(1,n);
isprime(1)=false;
p=2;
isprime(2*p:p:end)=false;
p=3;
while p^2<=n
while ~isprime(p) && p^2<=n;
p=p+1;
end;
if ~isprime(p)
break;
end ;
isprime(2*p:p:end)=false;
p=p+2;
disp('isprime(nth)')
end;
primesfound=find(isprime)
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!