#C2618. Largest Palindrome Product
Largest Palindrome Product
Largest Palindrome Product
Given an integer n, your task is to compute the largest palindrome number which is the product of two n-digit numbers. A palindrome is a number that reads the same forward and backward. If no such product exists or if n < 1, the output should be -1.
Let \(\text{min\_factor} = 10^{n-1}\) and \(\text{max\_factor} = 10^n - 1\). Your goal is to iterate over all pairs of n-digit numbers between these two values (inclusive) and find the largest product which is a palindrome.
For example:
- For n = 2, the expected output is 9009 (since 91 \(\times\) 99 = 9009).
- For n = 3, the expected output is 906609.
- For n = 1, the expected output is 9.
- For non-positive values of n, the output should be -1.
inputFormat
The input consists of a single integer n provided via standard input (stdin).
outputFormat
Output a single integer which is the largest palindrome product of two n-digit numbers. If no valid palindrome exists or if n < 1, output -1. The result should be printed to standard output (stdout).
## sample2
9009