zoj3665(枚举+二分)

Yukari's Birthday Time Limit: 2 Seconds      Memory Limit: 32768 KB

Today is Yukari's n-th birthday. Ran and Chen hold a celebration party for her. Now comes the most important part, birthday cake! But it's a big challenge for them to placen candles on the top of the cake. As Yukari has lived for such a long long time. Though she herself insists that she is a 17-year-old girl.

To make the birthday cake look more beautiful, Ran and Chen decide to place them liker ≥ 1 concentric circles. They placeki candles equidistantly on thei-th circle, wherek ≥ 2, 1 ≤ i ≤ r. And it's optional to place at most one candle at the center of the cake. In case that there are a lot of different pairs ofr andk satisfying these restrictions, they want to minimizer × k. If there is still a tie, minimize r.

Input

There are about 10,000 test cases. Process to the end of file.

Each test consists of only an integer 18 ≤ n ≤ 1012.

Output

For each test case, output r and k.

Sample Input

18
111
1111

Sample Output

1 17
2 10
3 10

Author: WU, Zejun
Contest: The 2012 ACM-ICPC Asia Changchun Regional Contest

本题没什么好的方法。解法很单一。不知道k,r,但知道k^i(1<=i<=r)=n-1或n,于是可以联想枚举法。18 ≤ n ≤ 1012      

大致可得r的范围2-40左右,枚举r,在此基础上用二分法拼凑k,注意题目的要求,r*k最小,若有多个,取r最小的那个。

枚举+二分,

 

你可能感兴趣的:(枚举,二分)