#GL0000310. Dãy số 2 (222)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy số 2 (222)
222
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Consider the sequence . The -th term is the positive decimal integer made of exactly digits, each of them equal to .
Given a positive integer , find the smallest index for which the -th term is divisible by . If no such term exists, print -1.
You must output the index, not the potentially enormous integer consisting of repeated digit .
Input
One line containing the positive integer .
Output
Print the smallest positive index of a term divisible by , or -1 if no such term exists.
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
1
Output
1
Explanation
The first term is , which is divisible by , hence the answer is .
Example 2
Input
7
Output
6
Explanation
The first six terms have remainders modulo . The first zero remainder occurs at index .
Example 3
Input
10
Output
-1
Explanation
Every term ends in digit , so none is divisible by , which would require the last digit to be .
Example 4
Input
999983
Output
999982
Explanation
The first term divisible by has digits equal to ; all shorter positive lengths produce nonzero remainders.