#P8036. [COCI 2015/2016 #7] Prosti
[COCI 2015/2016 #7] Prosti
Problem Description
There are queries. In each query, you are given positive integers . Define the set of all happy numbers as .
For each query, find a positive integer such that the interval contains exactly happy numbers. If no such exists, output .
Input Format
The first line contains an integer .
The next lines each contain three integers .
Output Format
Output lines, each line being the answer to the corresponding query.
3
1 1 1
2 0 2
3 1 1
1
8
4
3
4 1 1
5 2 3
5 0 3
6
4
24
4
7 2 5
6 1 1
10 4 5
6 2 2
6
20
5
4
Hint
Constraints
- For of the data, , , .
Hints and Notes
You are welcome to hack the self-written Special Judge by private message or by making a post.
This problem is translated from COCI 2015-2016 #7 Task 5 Prosti.
The score of this problem follows the original COCI settings, with a full score of .
Translated by ChatGPT 5