Skip to content
TheChatArchiveThe Chat Archive
DeepSeekDeepseek v3.2· deepseekHugging Face Frontier Reasoning Traces

You are given a positive integer x. Find any such 2 positive integers a and b such that…

  1. User

    You are given a positive integer x. Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x.

    As a reminder, GCD(a,b) is the greatest integer that divides both a and b. Similarly, LCM(a,b) is the smallest integer such that both a and b divide it.

    It's guaranteed that the solution always exists. If there are several such pairs (a, b), you can output any of them. Input

    The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases.

    Each testcase consists of one line containing a single integer, x (2 ≤ x ≤ 10^9).

    Output

    For each testcase, output a pair of positive integers a and b (1 ≤ a, b ≤ 10^9) such that GCD(a,b)+LCM(a,b)=x. It's guaranteed that the solution always exists. If there are several such pairs (a, b), you can output any of them.

    Example

    Input

    2 2 14

    Output

    1 1 6 4

    Note

    In the first testcase of the sample, GCD(1,1)+LCM(1,1)=1+1=2.

    In the second testcase of the sample, GCD(6,4)+LCM(6,4)=2+12=14.

  2. DeepSeek Assistant

    We are to solve the problem: given x, find any positive integers a, b such that gcd(a,b) + lcm(a,b) = x.

    Constraints: t up to 100, x up to 1e9.

    It's guaranteed that solution exists. Output any a,b with 1 ≤ a,b ≤ 1e9.

    We need to find a pair quickly for each test case.

    Let's denote d = gcd(a, b). Then we can write a = d * m, b = d * n, where m and n are positive integers with gcd(m,n)=1. Then lcm(a,b) = d * m * n (since lcm = ab / gcd = d^2mn / d = dm*n). So equation becomes:

    d + dmn = x => d*(1 + m*n) = x.

    Thus x must be divisible by d, and then m*n = x/d - 1. Also m and n are coprime.

    We need to choose d, m, n such that a = dm, b = dn are within 1e9. Since x up to 1e9, d can be chosen accordingly.

    Goal: For each x, find some a,b. There is always a solution.

    Observation: If we take a = 1, b = x-1? Let's test: gcd(1, x-1)=1, lcm(1, x-1)=x-1, sum= x? That would be 1+(x-1)=x, so (1, x-1) works if gcd(1, x-1)=1 indeed gcd(1, anything)=1, so always works! Wait, lcm(1, x-1) = x-1 because lcm(1, k)=k. So sum = 1 + (x-1) = x. Yes! So (1, x-1) is a solution? Let's test with x=2: (1,1) works (since x-1=1). For x=14: (1,13) gives gcd=1, lcm=13, sum=14, works. But sample output gave (6,4) for 14. So (1,13) is also valid. However check constraint: a,b positive integers and <=1e9. For x up to 1e9, x-1 ≤ 1e9-1, so valid. So simplest solution: output "1" and "x-1". That satisfies all conditions? Let's double-check: For x=2, output (1,1) works. For x=3, (1,2) works? gcd(1,2)=1, lcm=2, sum=3. Works. For x=1? x≥2 so fine. So indeed a trivial solution exists: a=1, b=x-1. But wait: is it always true that gcd(1, x-1) = 1? Yes, gcd(1, any) = 1. So lcm = x-1. Sum = 1 + (x-1) = x. So that's a solution.

    But is there any hidden constraint? The problem says "positive integers a and b" and "It's guaranteed that the solution always exists." This trivial solution seems to always exist. However, check if for x=2, (1,1) okay. For x=10^9, (1, 10^9-1) okay since b ≤ 10^9-1 < 10^9. So output fits.

    But wait: The sample for x=14 output (6,4) not (1,13). So both are acceptable. So we can output (1, x-1) for all cases? Let's ensure that the lcm(1, x-1) = x-1, correct because any number divided by 1. So sum = 1 + x-1 = x. Yes.

    Thus the solution is trivial. But why would they need a note? Possibly they want to avoid trivial? But no restrictions. So the answer is simply for each test case, output 1 and x-1.

    But careful: x can be 2 => x-1 =1, both positive. Good.

    Thus the problem is solved.

    Wait: Check if any pitfalls: For x = 10^9, b = 10^9-1 <= 10^9, okay. The output constraints say 1 ≤ a, b ≤ 10^9, so b=10^9-1 is fine.

    Thus simplest solution: for each x, print "1 " + (x-1). But we need to handle multiple test cases.

    However, let's double-check: Is it possible that x-1 could be zero? No, x≥2, so x-1≥1.

    Thus indeed trivial.

    But is there any nuance: The problem statement says "Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x." So (1, x-1) works.

    So answer.

    But perhaps there is a catch: lcm(1, x-1) is x-1 only if x-1 is positive, which it is. So done.

    Thus the solution: For each test case, read x, output "1 " + (x-1). For Python, we can just print(f"1 {x-1}").

    I will craft the final answer accordingly.

    But note: Sometimes in such problems, there might be an issue that a,b must be up to 10^9, but x can be 10^9, b=10^9-1 okay. All good.

    Thus final solution: O(t) time.

    I will produce the reasoning and code. ```python

    import sys

    def main(): data = sys.stdin.read().strip().split() if not data: return t = int(data[0]) out_lines = [] idx = 1 for _ in range(t): x = int(data[idx]); idx += 1 out_lines.append(f"1 {x-1}") sys.stdout.write("\n".join(out_lines))

    if name == "main": main()