Problem Description
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 place n candles on the top of the cake. as Yukari has lived for such a 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 like r ≥1 concentric circles. they place ki candles equidistantly on the I-th circle, where k ≥ 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 of r and k satisfying these restrictions, they want to minimize r × 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
Source
2012 Asia ChangChun Regional Contest
Enumerate r, and then calculate the corresponding k.
Because k> = 2 on the question, r is certainly not very big, just a second.
Note that the initial right boundary cannot be too large when two points are used. Otherwise, the calculation process will exceed long.
In addition, % lld is required for input and output on zoj during submission, while % I64d is used for hdu. Otherwise, Wrong Answer
Code:
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
# Include <math. h>
Long powLL (long a, int B ){
Long res = 1;
For (int I = 0; I <B; I ++)
Res * =;
Return res;
}
Int main (void ){
Long n, r, k;
While (scanf ("% lld", & n )! = EOF ){
R = 1;
K = n-1;
For (int I = 2; I <= 45; I ++ ){
Long ll, rr, mm;
Ll = 2;
Rr = (long) pow (n, 1.0/I );
While (ll <= rr ){
Mm = (long) (ll + rr)/2;
Long ans = (mm-powLL (mm, I + 1)/(1-mm );
If (ans = n | ans = N-1 ){
If (I * mm <r * k ){
R = I;
K = mm;
}
Break;
}
Else if (ans> n ){
Rr = mm-1;
}
Else {
Ll = mm + 1;
}
}
}
Printf ("% lld \ n", r, k );
}
Return 0;
}