Concealed Square
Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0, where each underscore represents a single digit.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Find the unique positive integer whose square has the form \(1\_2\_3\_4\_5\_6\_7\_8\_9\_0\), where each “\(\_\)†is a single digit.
Problem 206: Concealed Square
Mathematical Foundation
Theorem (Divisibility by 10). If has the form , then .
Proof. The last digit of is 0. Since , we must have (for if and , then or other nonzero residues mod 10). More precisely, requires and , hence .
Theorem (Residue Constraint mod 100). Write . Then has the prescribed form only if or , i.e., or .
Proof. With , we have . The pattern requires the digit at position 16 (0-indexed from the left in the 19-digit number) to be 9, which means the tens digit of must fit . Equivalently, the units digit of must be 9. Since iff or , we get or .
Lemma (Search Bounds). The value of satisfies .
Proof. The 19-digit square lies in the interval . Taking square roots:
Since must be divisible by 10, the upper bound rounds to .
Theorem (Uniqueness). There exists exactly one in the search range satisfying the pattern constraint.
Proof. The search is exhaustive over approximately candidates (values of in with or ). Computational verification confirms exactly one solution: , with , which matches the pattern .
Editorial
We lo = 1010101030 (first multiple of 10 in range with m ending in 3). Candidates are generated from the derived formulas, filtered by the required conditions, and processed in order until the desired value is obtained.
Pseudocode
Input: pattern 1_2_3_4_5_6_7_8_9_0
Output: the unique n such that n^2 matches the pattern
lo = 1010101030 (first multiple of 10 in range with m ending in 3)
For n = lo to hi, stepping by 100:
Complexity Analysis
- Time: candidate evaluations. Each evaluation involves one multiplication and at most 10 digit extractions, all .
- Space: .
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
// We need n such that n^2 has the form 1_2_3_4_5_6_7_8_9_0
// n must end in 30 or 70 (since n divisible by 10, and (n/10)^2 ends in 9)
// n^2 has 19 digits, so n is roughly 1.01e9 to 1.39e9
// Use __int128 or just unsigned long long (19 digits fits in ull)
// max n^2 ~ 1.93e18 which fits in unsigned long long (max ~1.84e19)
auto check = [](long long n) -> bool {
long long sq = n * n;
// Check pattern: digits at positions (from right):
// pos 0 -> 0, pos 2 -> 9, pos 4 -> 8, ..., pos 18 -> 1
// i.e., (sq / 10^(2k)) % 10 == (10 - k) for k=0..9, with digit 10-0=10->0 special
// Actually: the pattern from left is 1_2_3_4_5_6_7_8_9_0
// From right (position 0 = units): pos 0 = 0, pos 2 = 9, pos 4 = 8, ...
// pos 2*i should be (10 - i) % 10 for i = 0..9
for (int i = 0; i <= 9; i++) {
int digit = sq % 10;
int expected = (10 - i) % 10;
if (digit != expected) return false;
sq /= 100; // skip one digit (the underscore)
}
return true;
};
// Search range
long long lo = (long long)ceil(sqrt(1020304050607080900.0));
long long hi = (long long)floor(sqrt(1929394959697989990.0));
// Adjust lo to end in 30 or 70
for (long long n = lo; n <= hi; n++) {
int r = n % 100;
if (r == 30 || r == 70) {
lo = n;
break;
}
}
for (long long n = lo; n <= hi; n += 10) {
// n ends in X0, we want X=3 or X=7
int tens = (n / 10) % 10;
if (tens != 3 && tens != 7) continue;
if (check(n)) {
cout << n << endl;
return 0;
}
}
return 0;
}
"""
Problem 206: Concealed Square
Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0.
"""
import math
def check(n):
"""Check if n^2 matches the pattern 1_2_3_4_5_6_7_8_9_0."""
sq = n * n
s = str(sq)
if len(s) != 19:
return False
pattern = "1_2_3_4_5_6_7_8_9_0"
for i, c in enumerate(pattern):
if c != '_' and s[i] != c:
return False
return True
def solve():
lo = math.isqrt(1020304050607080900)
hi = math.isqrt(1929394959697989990)
# n must end in 30 or 70
# Start from hi and work down (answer is near upper bound)
# Or iterate up from lo
for n in range(lo, hi + 1):
r = n % 100
if r != 30 and r != 70:
continue
if check(n):
return n
return None
# More efficient: step by 40/60 alternating from a starting point ending in 30
def solve_fast():
lo = math.isqrt(1020304050607080900)
hi = math.isqrt(1929394959697989990)
# Align lo to end in 30
r = lo % 100
if r <= 30:
start = lo - r + 30
elif r <= 70:
start = lo - r + 70
else:
start = lo - r + 130
n = start
while n <= hi:
if check(n):
return n
# Alternate between 30 and 70 endings
if n % 100 == 30:
n += 40 # jump to next XX70
else:
n += 60 # jump to next XX30 (next hundred)
return None
answer = solve_fast()
print(answer)