All Tracks Math Number Theory Basic Number Theory-1 Problem

Closest Gift
Tag(s):

Very-Easy

Problem
Editorial
Analytics

You are on your way to find the gifts. All the gifts lie in your path in a straight line at prime numbers and your house is at 0.Given your current position find the closest gift to your position, and calculate the distance between your current position and gift and tell the distance.

SAMPLE INPUT
0
SAMPLE OUTPUT
2
Explanation

For the no.= 0, the output is 2.

The closest prime number to 0 is 2, so the answer is 2 - 0 = 2.

For number = 11, the output should be 0.

11 is a prime number, so the answer is 11 - 11 = 0.

Input/Output

[time limit] 3000ms [input] string number

Constraints: 0 ≤ int(number) ≤ 9 · 1014.

[output] integer

Time Limit: 3.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

Notifications
View All Notifications