#P16800. [蓝桥杯 2026 国 B] 方和质数
[蓝桥杯 2026 国 B] 方和质数
Problem Description
Xiao Lan is studying a special kind of prime number.
For a positive integer, add up all digits in its decimal representation to get its digit sum. If this positive integer satisfies both of the following conditions, Xiao Lan calls it a “square-sum prime”:
- The number is a prime number.
- The digit sum of the number is a perfect square.
For example, the digit sum of is , and is a prime number, so is a square-sum prime.
Now, given an interval and a positive integer , find the -th square-sum prime in the interval when sorted in increasing order. If there are fewer than square-sum primes in the interval, output .
Input Format
Input one line containing three integers .
Output Format
Output one line with one integer, representing the -th square-sum prime in the interval . If it does not exist, output .
2 100 3
79
2 10 1
-1
Hint
Sample Explanation 1
The square-sum primes in the interval are in order, so the -rd one is .
Sample Explanation 2
The prime numbers in the interval are . Their digit sums are , none of which are perfect squares, so output .
Constraints
For of the testdata, , .
For all testdata, , , .
Translated by ChatGPT 5