Skip to main content
12 of 13
added 161 characters in body
user avatar
user avatar

Shift the digits

Given a single positive integer (say x), find the smallest positive integer, after being multiplied by x, produces a result equivalent to shifting the positive integer. Under a formula, it basically means n * x = n shifted. Find n (n > 0).

Here's an example of shifting:

123456789 -> 912345678
abcdefghi -> iabcdefgh (letters = any 0~9 digit)
123       -> 312

Rules

  • Preceding zeros count after shifting. If the number is 10 and is multiplied by 0.1 (0.1 isn't a valid input), the result is 1, which isn't equal to 01 (10 after shifting).
  • Your code has to run on Try It Online without timing out.
  • If your number only has one digit, the shifted result is your number:
1 -> 1
4 -> 4
9 -> 9

Test cases

Just to show that it's possible ...

9 -> 10112359550561797752808988764044943820224719
(In this test case, x = 9 and n = 10112359550561797752808988764044943820224719.
n shifted =                      91011235955056179775280898876404494382022471)

Don't believe it? Try it online.

user92069