Cody

# Problem 44384. Find the nearest prime number

Solution 1293535

Submitted on 17 Oct 2017 by Thorsten Bartel
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))

y = 2 i = 1

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

y = 5 i = 1

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

y = 100 i = 1 y = 101 i = -2

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

y = 500 i = 1 y = 501 i = -2 y = 499 i = 3

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

y = 911 i = 1

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

y = 2500 i = 1 y = 2501 i = -2 y = 2499 i = 3 y = 2502 i = -4 y = 2498 i = 5 y = 2503 i = -6

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

y = 8000 i = 1 y = 8001 i = -2 y = 7999 i = 3 y = 8002 i = -4 y = 7998 i = 5 y = 8003 i = -6 y = 7997 i = 7 y = 8004 i = -8 y = 7996 i = 9 y = 8005 i = -10 y = 7995 i = 11 y = 8006 i = -12 y = 7994 i = 13 y = 8007 i = -14 y = 7993 i = 15

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

y = 100000 i = 1 y = 100001 i = -2 y = 99999 i = 3 y = 100002 i = -4 y = 99998 i = 5 y = 100003 i = -6

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

y = 1300000 i = 1 y = 1300001 i = -2 y = 1299999 i = 3 y = 1300002 i = -4 y = 1299998 i = 5 y = 1300003 i = -6 y = 1299997 i = 7 y = 1300004 i = -8 y = 1299996 i = 9 y = 1300005 i = -10 y = 1299995 i = 11 y = 1300006 i = -12 y = 1299994 i = 13 y = 1300007 i = -14 y = 1299993 i = 15 y = 1300008 i = -16 y = 1299992 i = 17 y = 1300009 i = -18 y = 1299991 i = 19 y = 1300010 i = -20 y = 1299990 i = 21 y = 1300011 i = -22 y = 1299989 i = 23

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

y = 179424710 i = 1 y = 179424711 i = -2 y = 179424709 i = 3 y = 179424712 i = -4 y = 179424708 i = 5 y = 179424713 i = -6 y = 179424707 i = 7 y = 179424714 i = -8 y = 179424706 i = 9 y = 179424715 i = -10 y = 179424705 i = 11 y = 179424716 i = -12 y = 179424704 i = 13 y = 179424717 i = -14 y = 179424703 i = 15 y = 179424718 i = -16 y = 179424702 i = 17 y = 179424719 i = -18

### Community Treasure Hunt

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

Start Hunting!