#GL0000300. Số chỉ gồm chữ số 1 (Ones)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số chỉ gồm chữ số 1 (Ones)
Ones
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Consider the positive decimal integers consisting exclusively of digit 1:
You are given a positive integer that is divisible by neither nor . Under this condition, some number in the sequence is divisible by .
Find the minimum number of digits of such a number. Output its length, not the potentially enormous integer itself.
Input
A single line containing positive integer .
Output
Print one positive integer: the minimum number of digit 1 characters required.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Examples 1
Input
3
Output
3
Explanation
Neither nor is divisible by , but , so the minimum length is .
Examples 2
Input
7
Output
6
Explanation
The six-digit repunit is . Lengths through have nonzero remainder, so the answer is .
Examples 3
Input
9901
Output
12
Explanation
A 12-digit repunit is divisible by , and no shorter repunit has remainder zero modulo .