[Reprinted please indicate the source] http://blog.csdn.net/mingyong_blog/article/details/39252363
Description
Enter a positive integer k and find all positive integers x> = Y, so that 1/k = 1/x + 1/y.
-
-
Input
-
-
Enter an integer N in the first line, which indicates that there are N groups of test data.
Enter a positive integer k in each of the next n rows.
Output
Output the corresponding K in order to find all the combinations that meet the condition 1/k = 1/x + 1/y.
Train of Thought Analysis
The key is how to process 1/k = 1/x + 1/Y. Because division is not easy to process, this formula has three Division operations, so it is converted into multiplication, convert to xy = Ky + kx.
The minimum value of X> = y is k + 1, and the value of X is obtained based on the value of Y. X = ky/(Y-k). As the value of Y increases, the value of X decreases until x <y,Break.
# Include <stdio. h> # include <stdlib. h> # include <string. h> # include <stdlib. h> int main () {INT cases; int K; int y; scanf ("% d", & cases); While (cases --) {scanf ("% d ", & K); For (y = k + 1; y ++) {int x = (k * Y)/(Y-k); If (x <Y) break; If (x * y) = K * (x + y) printf ("1/% d = 1/% d + 1/% d \ n ", k, x, y );}}}
[Notes 66] split count