#BS0000173. Tìm tất cả cặp số nghiệm của hàm ẩn (Find Positive Integer Solution for a Given Equation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tìm tất cả cặp số nghiệm của hàm ẩn (Find Positive Integer Solution for a Given Equation)
Find Positive Integer Solution for a Given Equation
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
You can query an undisclosed function of two positive integers. It is strictly increasing in each variable: and . The target is known. Find every positive integer pair with and . There may be no valid pairs.
PHOJ Extended interaction: The formula and function identifier stay private to the judge. You may print ? x y followed by a flush; the judge answers with the integer . To submit the final answer, print ! k, followed by exactly lines containing x y for the different valid pairs, in any order. At most function queries are allowed. Invalid queries, an incorrect protocol, or missing/extra pairs are rejected. This interactive protocol replaces the LeetCode CustomFunction interface for PHOJ.
Input
The judge first sends one line with the target integer . After each ? x y query, it replies on a separate line with the value . The function identifier is private and is not provided to the contestant.
Output
For a query, print ? x y on one line and flush. For the final answer, print ! k, then exactly lines, each with x y. All output pairs must be distinct and the set must contain every valid pair.
Subtasks
- Subtask 1 (20 points): ; queries have ; at most calls to a hidden function from the nine strictly increasing functions.
- Subtask 2 (30 points): ; queries have ; at most calls to a hidden function from the nine strictly increasing functions.
- Subtask 3 (50 points): ; queries have ; at most calls to a hidden function from the nine strictly increasing functions.
Examples
Input
5
Output
? 1 1
? 1 2
! 4
1 4
2 3
3 2
4 1
Explanation
In this demonstration, the hidden function is and the target is . The queries ? 1 1 and ? 1 2 return and , respectively. The valid pairs are , , , and ; each pair sums to . No other positive integer pair fits the target. After ! 4, print these four pairs. This illustrates the protocol only; the actual hidden function is not disclosed.