#SP0000101. Độ dài khoảng cách giữa hai nguyên tố (Prime Gap)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Độ dài khoảng cách giữa hai nguyên tố (Prime Gap)
Prime Gap
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Consider all prime numbers in increasing order. Two primes are consecutive if there is no prime strictly between them. Given an integer , output if itself is prime. Otherwise, find the consecutive primes surrounding and output the gap length . The length is the difference between the two bounding primes, not the number of composite numbers between them.
If lies between consecutive primes and , the result is even though fewer than composite numbers lie between them.
Input
One line contains an integer .
Output
Print when is prime; otherwise print the difference between the consecutive primes surrounding .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
10
Output
4
Explanation
The consecutive primes enclosing are and . The numbers lie between them. The prime gap length is , so the output is .