Happy 5th birthday, Cody! Since 5 is a prime number, let's have some fun looking for other prime numbers.
Given a positive integer x, find the nearest prime number. Keep in mind that the nearest prime may be less than x.
Examples
nearestprime(5) = 5 nearestprime(36) = 37 nearestprime(200) = 199
NOTE: You may ignore cases in which two prime numbers are equally close to x. (e.g., x=12 --> 11 and 13 are both primes).
Test case No. 5
x = 911;
y_correct = 911;
Should the nearest prime number for 911 have been 907?
how i can solve
which is wrong
Look. It's Size 80
I feel for you, typing in those endless arrays of prime numbers.
You have probably figured it out by now, but instead of typing in manually the vectors prim0 and prim1 and then checking memberships, you can just run the function 'isprime(x)' which will save you lots of space and time
3015 Solvers
946 Solvers
Sum all integers from 1 to 2^n
6566 Solvers
Given a 4x4 matrix, swap the two middle columns
360 Solvers
Find the dimensions of a matrix
273 Solvers