The smallest lucky multiple
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Given a positive integer \(n\).
As you know, there are only two lucky digits — \(4\) and \(7\). Accordingly, a number is lucky if its decimal representation contains only lucky digits. For example, \(47\) and \(77474\) are lucky numbers.
Find the smallest lucky number that is a multiple of \(n\), or state that it does not exist.
Input
The single line contains the integer \(n\).
Output
If the smallest lucky number divisible by \(n\) exists, print it. Otherwise, print
-1.
Constraints
\(1 \le n \le 10^6\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 11 | 44 |
| Input (stdin) | Output (stdout) |
|---|---|
| 8 | 744 |
| Input (stdin) | Output (stdout) |
|---|---|
| 2000 | -1 |
| Input (stdin) | Output (stdout) |
|---|---|
| 23 | 7774 |
Source: The Algo Battles 2024 - Етап 4
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|