Ctrl K

Ones-Only Multiple

Medium
An old display printer can only print the digit 1, so the only numbers it can produce are 1, 11, 111, 1111, and so on. Given a positive integer divisor, find the shortest of these numbers that is divisible by divisor and return how many digits it has. If no ones-only number is divisible by divisor, return -1. Keep in mind that the number itself can be huge, far too long to fit in a 64-bit integer.
Example 1
divisor=7 → 6

111111 = 7 × 15873, while none of the shorter ones-only numbers (1, 11, 111, 1111, 11111) is divisible by 7. The length is 6.

Example 2
divisor=5 → -1

A ones-only number always ends in 1, so it is never divisible by 5.

Example 3
divisor=37 → 3

111 = 3 × 37, so the answer is 3.

Constraints
  • 1 ≤ divisor ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNumber in Roman Numerals MediumFraction as a Decimal MediumNumbers Made of Twos, Threes and Fives MediumVertical Mirror Line MediumDigits From Scrambled Words Medium
loading Python…
Input
divisor=7
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.