Cody

# Problem 44384. Find the nearest prime number

Solution 1305361

Submitted on 20 Oct 2017 by Ashley Goddard
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = 0; y_correct = 2; assert(isequal(nearestprime(x),y_correct))

a = 0 b = 0 y = 2

2   Pass
x = 5; y_correct = 5; assert(isequal(nearestprime(x),y_correct))

a = 5 b = 5 y = 5

3   Pass
x = 100; y_correct = 101; assert(isequal(nearestprime(x),y_correct))

a = 100 b = 100 a = 99 b = 101 y = 101

4   Pass
x = 500; y_correct = 499; assert(isequal(nearestprime(x),y_correct))

a = 500 b = 500 a = 499 b = 501 y = 499

5   Pass
x = 911; y_correct = 911; assert(isequal(nearestprime(x),y_correct))

a = 911 b = 911 y = 911

6   Pass
x = 2500; y_correct = 2503; assert(isequal(nearestprime(x),y_correct))

a = 2500 b = 2500 a = 2499 b = 2501 a = 2498 b = 2502 a = 2497 b = 2503 y = 2503

7   Pass
x = 8000; y_correct = 7993; assert(isequal(nearestprime(x),y_correct))

a = 8000 b = 8000 a = 7999 b = 8001 a = 7998 b = 8002 a = 7997 b = 8003 a = 7996 b = 8004 a = 7995 b = 8005 a = 7994 b = 8006 a = 7993 b = 8007 y = 7993

8   Pass
x = 100000; y_correct = 100003; assert(isequal(nearestprime(x),y_correct))

a = 100000 b = 100000 a = 99999 b = 100001 a = 99998 b = 100002 a = 99997 b = 100003 y = 100003

9   Pass
x = 1300000; y_correct = 1299989; assert(isequal(nearestprime(x),y_correct))

a = 1300000 b = 1300000 a = 1299999 b = 1300001 a = 1299998 b = 1300002 a = 1299997 b = 1300003 a = 1299996 b = 1300004 a = 1299995 b = 1300005 a = 1299994 b = 1300006 a = 1299993 b = 1300007 a = 1299992 b = 1300008 a = 1299991 b = 1300009 a = 1299990 b = 1300010 a = 1299989 b = 1300011 y = 1299989

10   Pass
x = 179424710; y_correct = 179424719; assert(isequal(nearestprime(x),y_correct))

a = 179424710 b = 179424710 a = 179424709 b = 179424711 a = 179424708 b = 179424712 a = 179424707 b = 179424713 a = 179424706 b = 179424714 a = 179424705 b = 179424715 a = 179424704 b = 179424716 a = 179424703 b = 179424717 a = 179424702 b = 179424718 a = 179424701 b = 179424719 y = 179424719

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!