Problem:
Skyscraper "MinatoHarukas" Mr. Port plans to start a new business renting one or more floors
of the new skyscraper with one giga floors, MinatoHarukas.
 
He wants to rent as many vertically adjacent floors as possible, 
because he wants to show advertisement on as many vertically
adjacent windows as possible.

The rent for one floor is proportional to the floor number,
that is, the rent per month for the n -th floor is n times
that of the first floor.
Here, the ground floor is called the first floor in the American style,
and basement floors are out of consideration for the renting.

In order to help Mr. Port, you should write a program that computes
the vertically adjacent floors satisfying his requirement and
whose total rental cost per month is exactly equal to his budget. For example, when his budget is 15 units, 
with one unit being the rent of the first floor,
there are four possible rent plans,
1+2+3+4+5, 4+5+6, 7+8, and 15. 
For all of them, the sums are equal to 15.
Of course in this example the rent of maximal number of the floors 
is that of 1+2+3+4+5, that is, the rent from the first floor to the fifth floor. Input The input consists of multiple datasets,
each in the following format.   b    A dataset consists of one line,
the budget of Mr. Port b as multiples of the rent of the first floor. b is a positive integer satisfying 1 < b < 10 9 . The end of the input is indicated by a line containing a zero.
The number of datasets does not exceed 1000. Output For each dataset, output a single line containing two positive integers
representing the plan with the maximal number of vertically adjacent floors
with its rent price exactly equal to the budget of Mr. Port.
The first should be the lowest floor number and
the second should be the number of floors. Sample Input 15
16
2
3
9699690
223092870
847288609
900660121
987698769
999999999
0 Output for the Sample Input 1 5
16 1
2 1
1 2
16 4389
129 20995
4112949 206
15006 30011
46887 17718
163837 5994

Solution (Python):
while True:
  b = int(input())
  if b == 0:break
  x = b * 2
  for k in range(int(x ** (1 / 2)), 0, -1):
    if x % k == 0:
      if (-k + 1 + (x // k)) % 2 == 0:
        a = (-k + 1 + x // k) // 2
        if a > 0:
          print(a, k)
          break

Solution (Python):
while True:
    b = int(input())
    if b == 0:
        break
    n = 1
    ans = []
    while True:
        
        if n % 2 == 0:
            if b % n != 0:
                if b // n >= n // 2:
                    if (b / n * 10) % 5 == 0:
                        ans = [b // n - n // 2 + 1, n]
                else:
                    break
        else:
            if b % n == 0:
                if b // n - 1 >= (n - 1) // 2:
                    ans = [b // n - 1 - (n - 1) // 2 + 1, n]
                else:
                    break
        n += 1
        
    print(ans[0], ans[1])

Solution (Python):
import sys

def resolve(buget,num):
    return ((((2*buget)/num)-num+1)/2)

for buget in sys.stdin:
    buget = int(buget)
    if buget == 0 :
        break

    num = 1
    answer_floor = 1
    answer_num = 1
    answer = 0
    while (num*num)/2 < buget :
        
        answer = resolve(buget,num)
        if answer.is_integer():
            answer_floor = answer
            answer_num = num
        num = num + 1
    print(str(int(answer_floor)) + " " + str(answer_num))

Solution (Python):
from math import sqrt
def solve(B):
    ans = 0
    for L in range(1,int(sqrt(1+8*B))+2):
        
        a = (2*B+L*L-L)
        b = (2*L)
        if(a%b==0):
            u = a//b
            d = u - L + 1
            if(1<=d<=u):
                
                ans = L
                ans_d = d
            

    print(ans_d,ans)


def main():
    while(True):
        N=int(input())
        if(N):
            solve(N)
        else:
            break
if __name__ == "__main__":
    main()

Solution (Python):
import math

def main(b):
	if b == 0:
		return False
	for n in range(int(math.sqrt(2*b)), 0, -1):
		if 2*b % n == 0:
			a = (-n*n + n + 2 * b)/(2*n)
			if a >= 1 and a.is_integer():
				print(int(a), n)
				return True


while main(int(input())):
	pass

Solution (Python):


import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    while True:
        B = read_int()
        if B == 0:
            break
        print(*solve(B))


def solve(B):
    bb = 2 * B

    lb = 1
    ub = B + 1
    while ub - lb > 1:
        m = (lb + ub) // 2
        if m * m <= bb:
            lb = m
        else:
            ub = m

    n = lb
    while True:
        if bb % n == 0:
            k = bb // n
            if (k - n) % 2 == 1:
                return (k - n + 1) // 2, n
        n -= 1





DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()

Solution (Python):
from math import sqrt
li=[]
for i in range(10000):
    n=int(input())
    if n>0:
        m=2*n
        b=int(sqrt(2*m))
        for i in range(b,0,-1):
            if m%i==0:
                A=(m/i+1-i)
                if A%2==0 and A>0:
                    a=int(A/2)
                    li.append([a,i])
                    break
    if n==0:
        break
for hoge in li:
    print(*hoge)

Solution (Python):
while True:
    b = int(input())
    if b == 0:
        break
    tmp = 0
    results = {}
    for n in range(1, int((2*b)**(1/2))+1):
        tmp = ((2*b/n) - n + 1) / 2
        if int(tmp) == tmp:
            results[tmp] = n

    results = sorted(results.items(), key=lambda x: x[1], reverse=True)
    a, n = results[0][0], results[0][1]
    print(int(a), int(n))

Solution (Python):
import sys
input = sys.stdin.readline

def binary_search(num, start, end, l):
    if start == end:
        return start
    tmp = (start + end) // 2
    if l[tmp] <= num:
        return binary_search(num, tmp+1, end, l)
    else:
        return binary_search(num, start, tmp, l)

def main():
    MAX = int(1e9)
    check_list = [0]
    tmp = 0
    i = 1
    while True:
        tmp += i
        if tmp < MAX:
            check_list.append(tmp)
            i += 1
        else:
            break
    len_ = len(check_list)

    while True:
        b = int(input())
        if b == 0:
            break
        ans = 0
        start = binary_search(b, 0, len_-1, check_list)
        for i in range(start, 0, -1):
            if check_list[i] <= b:
                tmp = (b - check_list[i]) % i
                if tmp == 0:
                    print((b-check_list[i])//i+1, i)
                    break

if __name__ == "__main__":
    main()

Solution (Python):
import re
import sys
import math
import itertools
from sys import stdin

def main():
    """
     解答をこちらに
    """
    while 1:
        b = int(input())

        if b==0:
            return
        ans1 = b
        ans2 = 1
        for l in range(1, b+1):
            p = (b - l *(l-1)/2 )/l

            if p <1:
                break
            if p % 1==0:
                ans1 = int(p)
                ans2 = l
        print(ans1, ans2)

        
if __name__ == "__main__":
    main()

Solution (Python):
import math
def main(n):
    for i in range(int((1 + math.sqrt(1 + 8 * n)) // 2) + 1, 0, -1):
        if float.is_integer(n / i - (i - 1) / 2) and n / i - (i - 1) / 2 > 0:
            print(int(n / i - (i - 1) / 2), i)
            return

while 1:
    n = int(input())
    if n == 0:
        break
    main(n)

Solution (Python):
ans_list = []

while True:
    b = int(input())
    if b == 0:
        break
    h = 1
    ans = -1
    while h*(h-1)//2 <= b:
        if (b- h*(h-1)//2) % h == 0:
            n = (b- h*(h-1)//2) // h
            if n >= 1:
                ans = "{} {}".format(n, h)
        h += 1

    ans_list.append(ans)

for ans in ans_list:
    print(ans)

Solution (Python):
import math

while True:
    b = int(input())
    if b == 0:
        break

    maxfs = math.floor((-1 + math.sqrt(1 + 8 * b)) / 2)

    minf = 1000000001
    lenf = 0
    flag = False

    for lengthf in range(2, maxfs+1)[::-1]:
        a0 = int(lengthf * (lengthf + 1) / 2)

        if b == a0:
            minf = 1
            lenf = lengthf
            flag = True
            break

        if (b - a0) % lengthf != 0:
            continue

        n = int((b - a0) / lengthf)
        minf = n + 1
        lenf = lengthf
        flag = True
        break

    if not flag:
        minf = b
        lenf = 1

    print(minf, lenf)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def MAP(): return map(int, input().split())

ans = []
while 1:
	b = INT()
	if b == 0:
		break

	for n in range(int((2*b)**(1/2)), -1, -1):
		if (2*b - n**2 + n) % (2*n) == 0:
			a = (2*b - n**2 + n) // (2*n)
			break
	ans.append((a, n))

for a, n in ans:
	print(a, n)

Solution (Python):
import math

while True:
    b = int(input())
    if b == 0:
        break
    k_max = int(((-1 + math.sqrt(1 + 8 * b)) / 2))
    for k in range(k_max, 0, -1):
        if 2 * b % k == 0 and (2 * b / k + 1 - k) % 2 == 0:
            n = int((2 * b / k + 1 - k) / 2)
            print("{} {}".format(n, k))
            break

Solution (Python):

"""
n = int(input())
k = list("mcxi")
for i in range(n):
    d = {"m":0,"c":0,"x":0,"i":0}
    a,b  = input().split()
    a = list(a)
    b = list(b)
    a.insert(0,1)
    b.insert(0,1)
    for j in range(1,len(a)):
        if a[j] in k:
            if a[j-1] in k:
                d[a[j]] += 1
            else:
                d[a[j]] += int(a[j-1])
    for j in range(1,len(b))[::-1]:
        if b[j] in k:
            if b[j-1] in k:
                d[b[j]] += 1
            else:
                d[b[j]] += int(b[j-1])
            if d[b[j]] >= 10:
                l = b[j]
                while d[l] >= 10:
                    d[l] -= 10
                    l = k[k.index(l)-1]
                    d[l] += 1
    for j in k:
        if d[j]:
            if d[j] == 1:
                print(j,end = "")
            else:
                print(str(d[j])+j,end = "")
    print()
"""


"""
while 1:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    s = [list(map(int, input().split())) for i in range(h)]

    ans = 0
    for u in range(h):
        for d in range(u+2,h):
            for l in range(w):
                for r in range(l+2,w):
                    m = float("inf")
                    for i in range(u,d+1):
                        m = min(m,s[i][l],s[i][r])
                    for i in range(l,r+1):
                        m = min(m,s[u][i],s[d][i])
                    f = 1
                    su = 0
                    for i in range(u+1,d):
                        for j in range(l+1,r):
                            su += (m-s[i][j])
                            if s[i][j] >= m:
                                f = 0
                                break
                        if not f:
                            break
                    if f:
                        ans = max(ans,su)
    print(ans)
"""


"""
while 1:
    m,n = map(int, input().split())
    if m == n == 0:
        break
    d = {}
    ma = 7368791
    for i in range(m,ma+1):
        d[i] = 1
    z = m
    for i in range(n):
        for j in range(z,ma+1):
            if d[j]:
                z = j
                break
        j = 1
        while z*j <= ma:
            d[z*j] = 0
            j += 1
    for j in range(z,ma+1):
        if d[j]:
            print(j)
            break
"""


def factorize(n):
    if n < 4:
        return [1,n]
    i = 2
    l = [1]
    while i**2 <= n:
        if n%i == 0:
            l.append(i)
            if n//i != i:
                l.append(n//i)
        i += 1
    l.append(n)
    l.sort()
    return l
while 1:
    b = int(input())
    if b == 0:
        break
    f = factorize(2*b)
    for n in f[::-1]:
        a = 1-n+(2*b)//n
        if a >= 1 and a%2 == 0:
            print(a//2,n)
            break

Solution (Python):
while True:
    b=int(input())
    if b == 0: break
    
    
    nf = 1
    ans = (b,1)
    while True:
        d = b - (nf-1)*nf//2
        if d <= 0: break
        if d % nf == 0:
            ans = (d // nf, nf)
        nf += 1
    print("{0} {1}".format(ans[0],ans[1]))

Solution (Python):
import sys
import math
datasets = []
ans = []
while 1:
    n = int(input())
    if n == 0:
        break
    datasets.append(n)
for n in datasets:
    facts = []
    for x in range(1, int((math.sqrt(2*n)))+1 ):
        if 2*n%x == 0:
            facts.append(x)
    for x in reversed(facts):
        y = 2*n // x
        if (y-x)%2 == 1:
            ans.append((x, y))
            break
for i in range(len(datasets)):
    x = ans[i][0]
    y = ans[i][1]
    print("{} {}".format((y-x+1)//2, x))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n):
        t = int((n * 2) ** 0.5) + 1
        for i in range(t,1,-1):
            if i % 2 == 1:
                if n % i == 0 and  n // i > i // 2:
                    return '{} {}'.format(n//i-i//2, i)
            else:
                if n%i != 0 and n*2 % i == 0 and n // i + 1 > i // 2:
                    return '{} {}'.format(n//i-i//2+1, i)
        return '{} {}'.format(n, 1)

    while 1:
        n = I()
        if n == 0:
            break
        rr.append(f(n))
        

    return '\n'.join(map(str, rr))


print(main())

Solution (Python):
from itertools import product
A=[2*x-1 for x in range(2,50001)]
primes=[2]
while(1):
    if A[0] > 5000**0.5:
        primes += A
        break
    else:
        t=A[0]
        primes.append(t)
        A = [x for x in A if x%t !=0 ]
while(1):
    b = int(raw_input())*2
    M=b
    if b==0: break
    D=[]
    for a in primes:
        tmp=0
        while b%a == 0:
            tmp+=1
            b/=a
        if tmp!=0:
            D.append( [ a**p for p in range(tmp+1) ] )
    allp =  sorted( [reduce( lambda a,b:a*b ,d ) for d in product(*D) ] , reverse=True)
    for p in allp:
        n=p-1
        if (M/p-n)%2==0 and (M/p-n)/2>0:
            print (M/p-n)/2, p
            break

Solution (Python):
ans = []
while 1:
    b = int(input())
    if b == 0:
        break
    x = 1
    res = (1, 1)
    while x*x <= b:
        if b % x == 0:
            y = b // x
            if x % 2 == 1:
                if y - x//2 >= 1:
                    res = max(res, (x, y - x//2))
                if x//2 - y + 1 >= 1:
                    res = max(res, (2*y, x//2 - y + 1))
            if y % 2 == 1:
                if x - y//2 >= 1:
                    res = max(res, (y, x - y//2))
                if y//2 - x + 1 >= 1:
                    res = max(res, (2*x, y//2 - x + 1))
        x += 1
    b, a = res
    ans.append("%d %d" % (a, b))
print(*ans, sep='\n')