#GL0000319. Chữ số 3 kỳ diệu (The Magical 3)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chữ số 3 kỳ diệu (The Magical 3)
The Magical 3
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A positive integer may be represented in different integer bases . In any base , digit is a valid digit.
Find the smallest integer base such that the final (least significant) digit of the representation of in base is . If no such base exists, print the prescribed failure message.
For example, has last digit in base , but , so base is the minimum.
Input
One line contains the positive integer .
Output
Print the smallest suitable base . If no suitable base exists, print exactly No such base.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
11
Output
4
Explanation
Because , the smallest permitted base, , already works.
Example 2
Input
42
Output
13
Explanation
We have . Its divisors are , and the smallest one at least is .
Example 3
Input
2
Output
No such base
Explanation
In any base , the single digit of the number is , not .
Example 4
Input
3
Output
4
Explanation
The number is represented by the single digit in every base , so the minimum is .