EhAb AnD gCd (Codeforces 1325A)
Tags: Greedy, number theory

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 \le t \le 100)$$$  — the number of testcases.Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.

Output: For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 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.

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$$$.

Sample Inputs:
2
2
14

Sample Outputs:
1 1
6 4

Solution (Python):
from collections import *
from itertools import *
from bisect import *
from heapq import *
from math import ceil, prod, gcd, factorial
from time import time
mod = 10 ** 9 + 7
d = ((1, 0), (0, 1), (0, -1), (-1, 0))
alpha = 'abcdefghijklmnopqrstuvwxyz'

def KMPprefix(s):
    j = 0
    res = [0]
    for i in range(1, len(s)):
        while j and s[i] != s[j]:
            j = res[j - 1]
        j += s[i] == s[j]
        res.append(j)
    return res

def helper(s):
    prefix = KMPprefix(s)
    n = len(s)
    res = set([n])
    div = 0
    for (i, item) in enumerate(prefix):
        if item << 1 == i + 1:
            if s[:item] * (n // item) == s:
                div = item
                break
    if div:
        for i in range(div, n):
            if n % i == 0 and i % div == 0:
                res.add(i)
    return res
t = 1
t = int(input())
for _ in range(t):
    n = int(input())
    print(1, n - 1)

Solution (Python):
t = int(input())
for _ in range(t):
    x = int(input())
    a = 1
    b = x - 1
    print(a, b)

Solution (Python):
n = int(input())
arr = []
for i in range(n):
    x = int(input())
    arr.append('1' + ' ' + str(x - 1))
for i in arr:
    print(i)