Cody

# Problem 44384. Find the nearest prime number

Solution 3361568

Submitted on 24 Oct 2020 by Tejas Somadas
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))

p = 1 p = 2 i = -1 y = 2

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

p = 6 p = 7 i = 4 i = 3 y = 5

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

p = 101 i = 99 i = 98 i = 97 y = 101

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

p = 501 p = 502 p = 503 i = 499 y = 499

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

p = 912 p = 913 p = 914 p = 915 p = 916 p = 917 p = 918 p = 919 i = 910 i = 909 i = 908 i = 907 y = 911

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

p = 2501 p = 2502 p = 2503 i = 2499 i = 2498 i = 2497 i = 2496 i = 2495 i = 2494 i = 2493 i = 2492 i = 2491 i = 2490 i = 2489 i = 2488 i = 2487 i = 2486 i = 2485 i = 2484 i = 2483 i = 2482 i = 2481 i = 2480 i = 2479 i = 2478 i = 2477 y = 2503

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

p = 8001 p = 8002 p = 8003 p = 8004 p = 8005 p = 8006 p = 8007 p = 8008 p = 8009 i = 7999 i = 7998 i = 7997 i = 7996 i = 7995 i = 7994 i = 7993 y = 7993

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

p = 100001 p = 100002 p = 100003 i = 99999 i = 99998 i = 99997 i = 99996 i = 99995 i = 99994 i = 99993 i = 99992 i = 99991 y = 100003

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

p = 1300001 p = 1300002 p = 1300003 p = 1300004 p = 1300005 p = 1300006 p = 1300007 p = 1300008 p = 1300009 p = 1300010 p = 1300011 p = 1300012 p = 1300013 p = 1300014 p = 1300015 p = 1300016 p = 1300017 p = 1300018 p = 1300019 p = 1300020 p = 1300021 i = 1299999 i = 1299998 i = 1299997 i = 1299996 i = 1299995 i = 1299994 i = 1299993 i = 1299992 i = 1299991 i = 1299990 i = 1299989 y = 1299989

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

p = 179424711 p = 179424712 p = 179424713 p = 179424714 p = 179424715 p = 179424716 p = 179424717 p = 179424718 p = 179424719 i = 179424709 i = 179424708 i = 179424707 i = 179424706 i = 179424705 i = 179424704 i = 179424703 i = 179424702 i = 179424701 i = 179424700 i = 179424699 i = 179424698 i = 179424697 y = 179424719

### Community Treasure Hunt

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

Start Hunting!