链接:http://acm.hust.edu.cn/vjudge/problem/37234分析:x>=y和1/k=1/x+1/y=>y<=2k再加上x,y,k都是正整数可以推出y>k。
1 #include <iostream> 2 using namespace std; 3 4 int main() { 5 int k; 6 while (scanf("%d", &k) == 1) { 7 int num = 0, a[1000], b[1000]; 8 for (int y = k + 1; y <= 2 * k; y++) 9 if ((y * k) % (y - k) == 0) { 10 a[num] = (y * k) / (y - k); 11 b[num] = y; 12 num++; 13 } 14 printf("%d\n", num); 15 for (int i = 0; i < num; i++) 16 printf("1/%d = 1/%d + 1/%d\n", k, a[i], b[i]); 17 } 18 return 0; 19 }
时间: 2024-10-23 21:56:03