Cody

Problem 42749. Find the nearest prime

Created by Pooja Narayan in Community

Given a positive integer 'n', the task is to find a prime number greater than or equal to 'n'.

Example 1

If given 'n' is 10, then the closest prime number greater than 10 is 11 at a distance of 1. So 11 must be returned.

Example 2

If the given 'n' is 17, then the closest prime number is itself at a distance of 0. So 17 must be returned.

The returned prime number must be greater than or equal to 'n'.

Solution Stats

56.47% Correct | 43.53% Incorrect
Last solution submitted on Feb 07, 2019

Problem Comments

Recent Solvers35

Suggested Problems

Tags