You should pass the x values as a string. A double precision number cannot resolve all the digits that one needs to solve the test suite problems:
>> x = 321676750829977632;
>> x == x+1
ans =
1
I agree that there is an issue with the last test suite problem. passing it as a uint64 would work too.
Yep I got "Error: Out of memory. Type HELP MEMORY for your options." :-)
function y = euler003(x)
i=1;
while true
while ~isprime(i)
i=i+1;
end
%找到下一个的质数
if(i^2>=x)
y=x;
return;
end
%如果质数的平方大于当前数,说明x已经不能再分解为质数的乘积
while mod(x,i)==0
x=x/i;
end
%累除
i=i+1;
end
end
Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
%%
x = 600851475143;
y_correct = 6857;
assert(isequal(euler003(x),y_correct))
Error: The maximum value of n allowed is 2^32.
|
2 | Fail |
%%
x = 3916767508299776;
y_correct = 457;
assert(isequal(euler003(x),y_correct))
Error: The maximum value of n allowed is 2^32.
|
3 | Pass |
%%
x = 32167675;
y_correct = 1286707;
assert(isequal(euler003(x),y_correct))
|
4 | Fail |
%%
x = uint64(321676750829977632);
y_correct = 206830397;
assert(isequal(euler003(x),y_correct))
Error: The maximum value of n allowed is 2^32.
|
5 | Pass |
%%
x = 321676755;
y_correct = 5639;
assert(isequal(euler003(x),y_correct))
|
6 | Pass |
%%
x = 361125;
y_correct = 107;
assert(isequal(euler003(x),y_correct))
|
7 | Fail |
%%
x = 13916767508299776;
y_correct = 98779;
assert(isequal(euler003(x),y_correct))
Error: The maximum value of n allowed is 2^32.
|
9823 Solvers
345 Solvers
Generate a vector like 1,2,2,3,3,3,4,4,4,4
3613 Solvers
5112 Solvers
Given a square and a circle, please decide whether the square covers more area.
351 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!