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?
寻找第10001个素数.
%% find 10001's prime number
% ======use primes==========
% Elapsed time is 0.008245 seconds.
% ans =
% 104743
function result = euler7()
tic;
x = primes(200000);
result = x(10001);
toc;
end
用循环的办法:
% ======use loop===========
% Elapsed time is 5.486655 seconds.
% ans =
% 104743
function result = euler7()
n = 0;
result = 1;
while n<10001
result = result+1;
if isprime(result)
n = n+1;
end
end
end
No comments :
Post a Comment