#GL0000308. Chuỗi số 7 (Repsept)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chuỗi số 7 (Repsept)
Repsept
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Consider the sequence . Its -th term is the decimal integer consisting of exactly digits, all equal to .
Given a positive integer , find the smallest index at which a term of this sequence is divisible by . If no term is divisible by , print -1.
Indices start at . A term can have hundreds of thousands of decimal digits, even though it cannot be represented by an ordinary integer type.
Input
One line contains the integer .
Output
Print the smallest 1-based index of a term divisible by ; if none exists, print -1.
Subtasks
- Subtask 1 (20 points): , is an integer.
- Subtask 2 (30 points): , is an integer.
- Subtask 3 (50 points): , is an integer.
Examples
Example 1
Input
101
Output
4
Explanation
The remainders of , , modulo are . Since , the first divisible term occurs at index .
Example 2
Input
2
Output
-1
Explanation
Every term ends in digit , so each is odd and none can be divisible by .
Example 3
Input
999983
Output
999982
Explanation
The term consisting of digits is divisible by , and none of the shorter terms is divisible. Thus the answer is .