Gorodetskiy is a university student. He is really good at math and really likes solving engaging math problems. In the last exam, his professor gave him really hard math problems to solve, but Gorodetskiy could not solve them and failed the exam, so the professor told him: "These problems are a piece of cake, you should know them from school!" Here is one of the problems from the exam - you can decide if it really was an easy problem or not.
You are given a positive integer $M$. Let's call a positive integer $A$ an interesting number if there is at least one integer $B$ ($A \le B$) such that $A \cdot B$ is divisible by $M$ and $\frac{A \cdot B}{M} = A+B$.
Find all interesting numbers. Let's denote the number of such integers by $K$; it is guaranteed that $K \le 3*10^5$.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first and only line of each test case contains a single integer $M$.

-----Output-----
For each test case:
- First, print a line containing a single integer $K$.
- Then, print $K$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer ― the $i$-th interesting number in increasing order.

-----Constraints-----
- $1 \le T \le 10$
- $1 \le M \le 10^{14}$

-----Subtasks-----
Subtask #1 (20 points): $1 \le M \le 100$
Subtask #2 (20 points): $1 \le M \le 10^7$
Subtask #3 (60 points): original constraints

-----Example Input-----
2
3
6

-----Example Output-----
2
4
6
5
7
8
9
10
12

-----Explanation-----
Example case 1: There are two interesting numbers, $4$ and $6$. For $A = 4$, we can choose $B = 12$ and for $A = 6$, we can choose $B = 6$.

Source: codechef | Difficulty: HARD
Tags: Number theory

Complete search


Solutions:
primes = []
factors = []

def factorize(M):
	factors.clear()
	for i in range(0, len(primes)):
		if M == 1:
			break
		if M % primes[i] == 0:
			cnt = 0
			while M % primes[i] == 0:
				cnt = cnt + 1
				M = M / primes[i]
			factors.append(tuple([primes[i], 2 * cnt]))
	if M != 1:
		factors.append(tuple([M, 2]))
	return
ans = []

def solve(idx, val, threshold):
	if idx == len(factors):
		if val >= threshold:
			ans.append(val)
		return
	cnt = factors[idx][1]
	fact = factors[idx][0]
	mul = fact
	solve(idx + 1, val, threshold)
	for i in range(1, cnt + 1):
		solve(idx + 1, val * mul, threshold)
		mul = mul * fact

def find_sol():
	M = int(input())
	factorize(M)
	solve(0, 1, M)
	ans.sort()
	ans.reverse()
	print(len(ans))
	for i in range(0, len(ans)):
		x = M * M / ans[i]
		x = x + M
		print(int(x))
	ans.clear()
sieve = [True] * 10000005
for i in range(2, 10000000 + 1):
	if sieve[i] == True:
		primes.append(i)
		j = i * i
		while j <= 10000000:
			sieve[j] = False
			j = j + i
t = int(input())
while t > 0:
	t = t - 1
	find_sol()


T = int(input())
for t in range(T):
	M = int(input())
	A = []
	for a in range(M + 1, 2 * M + 1):
		b = a * M / (a - M)
		if float(a + b).is_integer() == True and b > 0:
			A.append(a)
	print(len(A))
	for i in range(len(A)):
		print(A[i])


t = int(input())
m = [int(input()) for i in range(t)]
for i in m:
	c = 0
	ANS = []
	if i % 2 != 0:
		for a1 in range(i + 1, 2 * i + 1, 2):
			intp = a1 * i / (a1 - i)
			if intp >= a1 and a1 * i % (a1 - i) == 0:
				c = c + 1
				ANS.append(a1)
	else:
		for a1 in range(i + 1, 2 * i + 1, 1):
			intp = a1 * i / (a1 - i)
			if intp >= a1 and a1 * i % (a1 - i) == 0:
				c = c + 1
				ANS.append(a1)
	ANS.sort()
	print(c)
	for j in ANS:
		print(j)


from math import sqrt

def solve(pos, mul):
	if pos == sz:
		ans.append(mul + N)
		return
	__pow = 1
	for i in range(ls[pos][1] + 1):
		if mul > N // __pow:
			break
		solve(pos + 1, mul * __pow)
		__pow *= ls[pos][0]
for _ in range(int(input())):
	n = int(input())
	(N, sq) = (n, int(sqrt(n)))
	ls = list()
	ans = list()
	for i in range(2, sq + 1):
		if n % i == 0:
			Count = 0
			while n % i == 0:
				Count += 2
				n //= i
			ls.append([i, Count])
	if n != 1:
		ls.append([n, 2])
	sz = len(ls)
	solve(0, 1)
	ans.sort()
	print(len(ans))
	print(*ans, sep='\n')


from math import sqrt

def sol(p, m):
	if p == s:
		ans.append(m + N)
		return
	__pow = 1
	for i in range(ls[p][1] + 1):
		if m > N // __pow:
			break
		sol(p + 1, m * __pow)
		__pow *= ls[p][0]
for _ in range(int(input())):
	n = int(input())
	(N, sq, ls, ans) = (n, int(sqrt(n)), list(), list())
	for i in range(2, sq + 1):
		if n % i == 0:
			Count = 0
			while n % i == 0:
				Count += 2
				n //= i
			ls.append([i, Count])
	if n != 1:
		ls.append([n, 2])
	s = len(ls)
	sol(0, 1)
	ans.sort()
	print(len(ans))
	print(*ans, sep='\n')


import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
prime = []
ind = 2
aa = [-1] * 10 ** 4

def func(ind, prod):
	nonlocal p, ss, ll
	if ind == len(p):
		ll.append(prod)
		return ''
	po = prod
	for i in range(p[ind][1] + 1):
		if po > m:
			break
		func(ind + 1, po)
		po *= p[ind][0]
while ind < 10 ** 4:
	if aa[ind - 1] == -1:
		prime.append(ind)
		aa[ind - 1::ind] = [0] * len(aa[ind - 1::ind])
	ind += 1
for _ in range(t):
	m = int(input())
	p = []
	ind = 0
	mm = int(m ** 0.5)
	n = m
	while prime[ind] <= mm + 1:
		count = 0
		while True:
			if n % prime[ind] == 0:
				count += 2
				n //= prime[ind]
			else:
				break
		if count > 0:
			p.append([prime[ind], count])
		ind += 1
		if ind == len(prime):
			break
	if n != 1:
		p.append([n, 2])
	ss = []
	ll = []
	func(0, 1)
	ll.sort()
	print(len(ll))
	for i in ll:
		print(i + m)


t = int(input())
m = [int(input()) for i in range(t)]
print('')
for i in m:
	arr = []
	count = 0
	for a in range(i + 1, i * 2 + 1):
		inpX = i * a / (a - i)
		if inpX >= a and i * a % (a - i) == 0:
			count = count + 1
			arr.append(a)
	print(count)
	for j in arr:
		print(j)


def interesting_nums(m):
	nums = []
	for x in range(m + 1, 2 * m + 1):
		if x * m % (x - m) == 0:
			nums.append(x)
	return nums

def main():
	T = int(input())
	for _ in range(T):
		num_list = interesting_nums(int(input()))
		print(len(num_list))
		for num in num_list:
			print(num)
main()


import sys
sys.setrecursionlimit(10 ** 8)
t = int(input())
m = [int(input()) for i in range(t)]

def rec(a, m, list1):
	b = a * m / (a - m)
	if b >= a and a * m % (a - m) == 0 and (a <= 2 * m):
		list1.append(a)
		a = a + 1
		rec(a, m, list1)
	elif a <= 2 * m:
		a = a + 1
		rec(a, m, list1)
for i in m:
	c = 0
	a = i + 1
	ANS = []
	rec(a, i, ANS)
	print(len(ANS))
	ANS.sort()
	for j in ANS:
		print(j)


t = int(input())
m = [int(input()) for i in range(t)]
for i in m:
	c = 0
	ANS = []
	for a in range(i + 1, 2 * i + 1, 1):
		intp = a * i / (a - i)
		if intp >= a and a * i % (a - i) == 0:
			c = c + 1
			ANS.append(a)
	print(c)
	for j in ANS:
		print(j)


for i in range(int(input())):
	m = int(input())
	l = []
	p = m ** 2
	ans = 0
	for i in range(1, m + 1):
		if p % i == 0:
			ans += 1
			l.append(i + m)
	print(ans)
	for i in l:
		print(i)


n = []
for i in range(int(input())):
	n.append(int(input()))
for m in n:
	r = []
	c = 0
	for a in range(m + 1, 2 * m + 1):
		b = a * m // (a - m)
		if a * b % m == 0:
			c += 1
			r.append(a)
	print(c)
	for a in r:
		print(a)


import math

def solve(pos, mul):
	if pos == len(ls):
		ans.append(mul)
		return
	po = 1
	for i in range(ls[pos][1] + 1):
		if mul * po > z:
			break
		solve(pos + 1, mul * po)
		po *= ls[pos][0]
for _ in range(int(input())):
	n = int(input())
	z = n
	ls = []
	ans = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			Count = 0
			while n % i == 0:
				Count += 2
				n //= i
			ls.append([i, Count])
	if n != 1:
		ls.append([n, 2])
	solve(0, 1)
	ans.sort()
	print(len(ans))
	for i in ans:
		print(i + z)


from math import sqrt

def prime_facs(n):
	l = [1]
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			l.append(i)
	return l
for a0 in range(int(input())):
	n = int(input())
	x = prime_facs(n ** 2)
	print(len(x))
	for i in x:
		print(i + n)