1. Title Description: Click to open the link
2. Problem solving ideas: According to the title description, you can solve the range of Y is 1≤y≤2k. The x=ky/(y-n) can then be obtained. Note that X is greater than 0 and is an integer.
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std; #define N 50000int U[n], V[n];int main () { Freopen ("T.txt", "R", stdin); int N;while (~SCANF ("%d", &n)) {int cnt = 0;int len = 2 * n;for (int y = 1; y <= len; y++) {if (y-n > 0 && n*y% (y-n) = = 0) {int x = n*y/(y-n); u[cnt] = x, v[cnt++] = y;}} printf ("%d\n", CNT), for (int i = 0; i < cnt; i++) printf ("1/%d = 1/%d + 1/%d\n", N, U[i], v[i]);} return 0;}
Example 7-3 fractional Split UVa10976