PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000017. Đoạn nguyên tố ngắn nhất (Prime Segment)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đoạn nguyên tố ngắn nhất (Prime Segment)
Prime Segment
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer , find an integer interval containing (), where both endpoints and are primes. Minimize its length . Equal endpoints are allowed: if itself is prime, is valid.
Input
One line contains the integer .
Output
Print two integers and , separated by a space, specifying the shortest prime-ended interval containing .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
10
Output
7 11
Explanation
The number is composite. The closest prime to its left is and the closest prime to its right is . Therefore contains , and neither endpoint can be moved closer while remaining prime.
Input
97
Output
97 97
Explanation
The number is prime. Taking yields length , the minimum possible.