x+y = n, x*y = m;
y = n - x;
x * ( n - x) = m
nx - x^2 = m;
x^2 - nx + m = 0;
△ = sqrt(n^2 - 4m)
要有整数解即△需要为可开方数即可。
/* HDU 2092 整数解 --- 水题 */ #include <cstdio> #include <cmath> int main() { double n, m; while (scanf("%lf%lf", &n, &m) == 2 && (n+m)){ n = n*n - 4 * m; m = (int)sqrt(n); if (m*m == n){ printf("Yes "); } else{ printf("No "); } } return 0; }