Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Smallest number such that concatenation is a square

Challenge

Write a program or function that takes a number \$n\$ and returns the smallest \$k\$ such that concatenation \$n'k\$ is a square. This sequence is described by A071176 on the OEIS.

I/O Examples

input --> output

1   -->    6 (4^2)
10  -->    0 (10^2)
35  -->  344 (188^2)
164 -->  836 (406^2)
284 --> 2596 (1686^2)

Rules

Answer*

Cancel
5
  • \$\begingroup\$ Modern 6 with Δ«Å²Nα. \$\endgroup\$
    – Grimmy
    Commented Jan 17, 2020 at 12:40
  • 3
    \$\begingroup\$ Actually my suggested 6 fails for 183673469387755102041 (yes this is the smallest counter-example I could find). \$\endgroup\$
    – Grimmy
    Commented Jan 17, 2020 at 12:48
  • \$\begingroup\$ @Grimmy I was actually trying to find a counter example where n concatted with n in the first iteration would be square, but my test program timed out. That's unfortunate, but still very original approach! \$\endgroup\$ Commented Jan 17, 2020 at 12:49
  • \$\begingroup\$ @Grimmy: I'm not sure what your program does precisely, but it seems to me 13223140496 might be a smaller counterexample, as I expect an answer of 9685186064? \$\endgroup\$
    – A. Rex
    Commented Jan 18, 2020 at 3:13
  • \$\begingroup\$ @A.Rex Indeed, any number that is a square when concatenated to itself will be a counter-example. Those are fairly rare. \$\endgroup\$
    – Grimmy
    Commented Jan 18, 2020 at 10:52