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

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 in JAVA (judge verdict: Accepted)

import java.util.Scanner;

public class Main {

	static int BinarySearch(long low, long high, long b) {
		// low <= ? < high
		long mid = 0;
		while(low < high) {
			mid = (low + high)/2;
			long ans = mid * mid + mid;
			if(ans == b)	return (int)mid;
			else if(ans < b) low = mid+1;
			else	high = mid;
		}
		return (int)mid;
	}

    public static void main(String[] args) throws Exception {
    	try(Scanner sc = new Scanner(System.in)) {
    	/*
    	 1. (aを最小値1として)lengthのmaxを二分探索で探してaを後から求める 
    	 2. lengthを0から線形探索してa<=0になる一歩手前を求める。
    	 ** lengthを最大値なにかで仮定できないから,aのminを二分探索で探すことはできない
    	 
    	 時間がかかる最初に考えたもの:
    	 	aを1から代入していってlengthを二分探索で求めていた。
    	 	
    	 */

//			1.
    		while(true) {
    			long b = sc.nextLong();
    			if(b == 0) break;
    			b *= 2;
    			int max = BinarySearch(1, (long)Math.sqrt(b)+2, b);
    			int size = 1;
    			int a = 0;
    			for(size = max; size > 0; size--) {
    				if(b%size != 0)	continue;
    				else if((b/size - size + 1)% 2 != 0)	continue;
    				a = (int)(b/size - size + 1)/2;
    				break;
    			}
    			System.out.println(a+" "+size);
    		}
//    		2.
//    		while(true) {
//    			int b = sc.nextInt();
//    			if(b == 0) break;
//    			long length = 0;
//    			int a = 0;
//    			for(int size=0; size<b; size++) { //size大きいほど、aが小さい
//    				int x = 2*b/(size+1) - (size+1) + 1;
//    				if(2*b%(size+1) != 0)	continue;
//    				else if(x % 2 != 0)	continue;
//    				else if(x <= 0)	break;
//    				a = x/2;
//    				length = size+1;
//    			}
//    			System.out.println(a + " " + length);
//    		}

    	}
    }
}