spoj#PONY6. Toward Infinity
Toward Infinity
Story: Twilight Sparkle was working on some formulas when she came across a strange pattern.
When she added 1/2 + 1/4 + 1/8 + ..., she saw that it kept getting closer and closer to 1.
She was able to figure out that problem and a few more, but there are others that are too difficult. She needs your help.
Problem Statement
Given k and r, integers, find
Sum from n = 1 to infinity of n^k / r^n.
Also you must output the exact value, as a fraction in lowest terms.
Input
You will be given a number T on the first line. The following T lines will be of the form
S k r
where S is a String label with no spaces, and both k and r are as described above.
Output
Your output will contain T lines of the form
S N / D
where S is the label you were given in the input, N is the numerator of the answer, and D is the denominator. D may be 1.
To be more precise, if the fraction is negative, then output the negative sign next to N.
Example
Input: 6 Case1: 0 2 Case2: 0 3 Case3: 0 -3 Label: 2 9 Otherlabel: 12 16 Biggest: 50 -555 Output: Case1: 1 / 1 Case2: 1 / 2 Case3: -1 / 4 Label: 45 / 256 Otherlabel: 268201436794928 / 320361328125 Biggest: -71542844799237379223056641850683038399677651990786654293842285446351016224553939010882650681431892067495137019178862799169155069446928707568453465 /
7086055907083154841158073677533359179964732523333455695465110902606507148230087594593
20274728690683789654784801111318621847552
Note: The output for each case should all be on one line. It is split in the final case here for readability.
Bounds
T <= 10000
0 <= k <= 50
1 < |r| <= 1000
The timelimit per case is ~x5 my Java solution.